XML generation is much easier now in C#. You can use System.Xml.Linq namespace to create XML content much faster and easy.
lets look at the following XML.
Create XML using Linq to XML
Following describes how to create the above xml using xElements.
xml.ToString()
Save XML File using Linq to XML
in generally there should be a xml declaration when we are saving the file. as an example
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
So create a file like that add following code to bottom of the above code.
lets look at the following XML.
<Customers> <Customer id="1" orderdate="4/1/1968">Paul Koch</Customer> <Customer id="2" orderdate="7/5/1988">Bob Kelly</Customer> <Customer id="3" orderdate="3/24/1990">Joe Healy</Customer> </Customers>
Create XML using Linq to XML
Following describes how to create the above xml using xElements.
xml.ToString()
Save XML File using Linq to XML
in generally there should be a xml declaration when we are saving the file. as an example
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
So create a file like that add following code to bottom of the above code.
XDocument Xdoc = new XDocument(); XDeclaration Xdec = new XDeclaration("1.0", "utf-8", "yes"); Xdoc.Declaration = Xdec; Xdoc.Add(xml); Xdoc.Save(@"C:\sample.xml"); |
Comments