Get the root element of the XML Tree for document in CSharp

Description

The following code shows how to get the root element of the XML Tree for document.

Example


  /*  w ww .java 2 s.  c o m*/
  
  
   
using System;
using System.IO;

using System.Linq;
using System.Xml.Linq;
using System.Xml;
using System.Collections;
using System.Collections.Generic;
public class MainClass
{
    public static void Main()
    {
        XDocument doc = new XDocument(
            new XComment("This is a comment."),
            new XElement("RootNode",
                new XElement("Book",
                    new XElement("Title", "C#"),
                    new XElement("Author", "No Name")
                )
            ),
            new XComment("This is another comment.")
        );
        Console.WriteLine(doc.Root.Name.ToString());
    }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style