Adding an element to the document : Xml Creation « XML « C# / CSharp Tutorial






using System;
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);
  }    
}

 Some Value M








30.1.Xml Creation
30.1.1.Create XML document by specifying the elements
30.1.2.Generate Xml Document
30.1.3.Generate XML Document with attributes
30.1.4.Helper method for generating the Xml document
30.1.5.Adding an element to the document