new XmlDocument() : XmlDocument « System.Xml « C# / C Sharp by API






new XmlDocument()

  

using System;
using System.Collections;
using System.Data;
using System.Xml;

public class MainClass {
   public static void Main() {
      XmlDocument doc = new XmlDocument();

      XmlElement root = doc.CreateElement( "books" );
      doc.AppendChild( root );

      XmlElement eltBook = doc.CreateElement( "book" );
      root.AppendChild( eltBook );

      XmlElement eltTitle = doc.CreateElement( "title" );
      eltTitle.AppendChild( doc.CreateTextNode( "myTitle" ) );
      eltBook.AppendChild( eltTitle );

      XmlElement eltAuthor = doc.CreateElement( "author" );
      eltAuthor.AppendChild( doc.CreateTextNode(  "myAuthor" ) );
      eltBook.AppendChild( eltAuthor );

      XmlElement eltPrice = doc.CreateElement( "price" );
      eltPrice.AppendChild( doc.CreateTextNode(  "10.0" ) );
      eltBook.AppendChild( eltPrice );

      Console.WriteLine( doc.OuterXml );
   }
}

   
    
  








Related examples in the same category

1.XmlDocument.AppendChild(XmlNode docNode)
2.XmlDocument.CreateComment(String comments)
3.XmlDocument.CreateElement
4.XmlDocument.CreateXmlDeclaration
5.XmlDocument.LoadXml(String xmlString)
6.XmlDocument.Save()
7.XmlDocument.SelectNodes
8.XmlDocument.SelectSingleNode