Using XmlTextWriter


Using XmlTextWriter

Name spaces to be used
using System.Xml;


string filename = "emp.xml";
XmlTextWriter tw = new XmlTextWriter(filename, null);
tw.Formatting = Formatting.Indented;
tw.WriteStartDocument();
tw.WriteStartElement("employee");
tw.WriteElementString("eno", "101");
tw.WriteElementString ("ename","ganesh");
tw.WriteEndDocument();
tw.Flush();
tw.Close();



Explanation:

The above is a simple code snippet which is used to write data into XML file.The object of XmlTextWriter is used to do the job.

WriteStartDocument:It marks the start of XML document.
WriteStartElement:It starts the first element in the XML document.
WriteElementString:It provides the data for the child node in first element.
WriteEndDocument:It marks the end of document.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: