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.