How to write an Xml file using Xml Writer?

Posted by Tripati_tutu under ASP.NET category on | Points: 40 | Views : 2662
To write an Xml file using Xml Writer, you need to import the namespace that is
using System.Xml;
Because the XmlWriter and XmlTextWriter classes are defined in that namespace.

So for creation of an Xml file, you need to have the constructor of the XmlTextWriter class.
After that you just create a xml file in your application as "SampleTestXml.xml" in the directory like "E:\XmlApplication"
XmlTextWriter xmlWriter = new XmlTextWriter("E:\\XmlApplication\SampleTestXml.xml", null);

If you want to display the xml content, then pass the Console.Out as a parameter of the constructor.
XmlTextWriter writer = new XmlTextWriter(Console.Out);

Comments or Responses

Login to post response