- private void button1_Click(object sender, EventArgs e)
- {
- // Creates an instance of the System.Xml.XmlTextWriter class using the specified file.
- XmlTextWriter textWriter = new XmlTextWriter(@"C:\xmlfile.xml", null);
- // Writes the XML declaration with the version "1.0".
- textWriter.WriteStartDocument();
- // Write comments
- textWriter.WriteComment("First Comment for XmlTextWriter Sample Example");
- // Write first element
- textWriter.WriteStartElement("Student");
- textWriter.WriteStartElement("Document", "Test", "RECORD");
- // Write next element Name
- textWriter.WriteStartElement("Name");
- textWriter.WriteString("Rajendra");
- textWriter.WriteEndElement();
- // Write element Address
- textWriter.WriteStartElement("Address");
- textWriter.WriteString("Bangalore");
- textWriter.WriteEndElement();
- // Write element Pincode
- textWriter.WriteStartElement("Pincode");
- textWriter.WriteString("560066");
- textWriter.WriteEndElement();
- // WriteChars
- char[] ch = new char[3];
- ch[0] = 'R';
- ch[1] = 'A';
- ch[2] = 'J';
- textWriter.WriteStartElement("Char");
- textWriter.WriteChars(ch, 0, ch.Length);
- textWriter.WriteEndElement();
- // Ends the document.
- textWriter.WriteEndDocument();
- // close writer
- textWriter.Close();
- }
Result


Join the conversation! Your thoughts help the community grow.