Comments create

In this chapter you will learn:

  1. Adding a new comment node to the document

Adding a new comment node to the document

using System;// j ava2s.c  om
using System.Xml;

class MainClass
{
  static void Main(string[] args)
  {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml("<Record> Some Value </Record>");

        XmlNode node1 = xmlDoc.CreateComment("DOM Testing Sample");
    xmlDoc.AppendChild( node1);

    node1 = xmlDoc.CreateElement("FirstName");
    node1.InnerText = "M";
    xmlDoc.DocumentElement.AppendChild(node1);

    xmlDoc.Save(Console.Out);
  }    
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Add the processing instruction
Home » C# Tutorial » XML
Parse XML file
Parse XML String
Parse XML from URL
Element create
Attribute create
Comments create
XProcessingInstruction
XmlReader
Read double value from XML
XmlReader
XmlReaderSettings
XML formatter
XmlSerializer
XmlTextReader
XmlTextWriter
XmlWriter
XmlWriterSettings
Output XML to console