XML Write: comment, start element, end element, attribute : XML Write « XML « C# / C Sharp






XML Write: comment, start element, end element, attribute

 
using System;
using System.Xml;

public class TestXMLWriter{
  static void Main(string[] args)
  {
    XmlTextWriter writer = new XmlTextWriter("test.xml", new System.Text.ASCIIEncoding());
    writer.Formatting = Formatting.Indented;
    writer.Indentation = 4;
    writer.WriteStartDocument();
    writer.WriteComment("Comment");
    writer.WriteStartElement("ElementName", "myns");
    writer.WriteStartAttribute("prefix", "attrName", "myns");
    writer.WriteEndAttribute();
    writer.WriteElementString("ElementName", "myns", "value");
    writer.WriteEndElement();
    writer.WriteEndDocument();
    writer.Flush();
    writer.Close();
  }
}



           
         
  








Related examples in the same category

1.Create XML document with XmlWriter
2.Read and Write XML Without Loading an Entire Document into MemoryRead and Write XML Without Loading an Entire Document into Memory
3.Writing XML with the XmlWriter ClassWriting XML with the XmlWriter Class
4.Write To XML File
5.Illustrates the XmlTextWriter class
6.Write XML document to console
7.Create XmlWriter using the static XmlWriter.Create method.