65.9K
CodeProject is changing. Read more.
Home

System.XML namespace

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Oct 11, 2013

CPOL
viewsIcon

7210

XML namepace has XmlWriter class to write to XML file. Code in C#:using System.XML; //Add this namespace to use XmlWriter and XmlReader

XML namepace has XmlWriter class to write to XML file.

 Code in C#:

using System.XML; //Add this namespace to use XmlWriter and XmlReader classes

StringBuilder sb = new StringBuilder();

XmlWriter xwrite = XmlWriter.Create("c:\\sample.xml"); // here you can provide the path for the xml file.

//If you want to write to a string instead of file.Replace the above line with the following line.

//XmlWriter xwrite = XmlWriter.Create(sb);

writer.WriteStartDocument(true);

 

writer.WriteStartElement(
"USERNAME");writer.WriteString("Admin");

writer.WriteEndElement();

 

 

 

writer.WriteEndDocument();

writer.Flush();

writer.Close();