XmlTextWriter Represents a writer that provides a fast, non-cached, forward-only way of generating streams or files containing XML data. XmlTextWriter renders XML data to a string. This string remains in the memory of the C# program. XmlTextWriter is useful for in-memory generation of XML.
- private void button1_Click(object sender, EventArgs e)
- {
-
- XmlTextWriter textWriter = new XmlTextWriter(@"C:\xmlfile.xml", null);
-
- textWriter.WriteStartDocument();
-
- textWriter.WriteComment("First Comment for XmlTextWriter Sample Example");
-
- textWriter.WriteStartElement("Student");
- textWriter.WriteStartElement("Document", "Test", "RECORD");
-
- textWriter.WriteStartElement("Name");
- textWriter.WriteString("Rajendra");
- textWriter.WriteEndElement();
-
- textWriter.WriteStartElement("Address");
- textWriter.WriteString("Bangalore");
- textWriter.WriteEndElement();
-
- textWriter.WriteStartElement("Pincode");
- textWriter.WriteString("560066");
- textWriter.WriteEndElement();
-
- 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();
-
- textWriter.WriteEndDocument();
-
- textWriter.Close();
- }
Result