There are situations where some time we want to get root element of XML file or document. We can get this root element and root element name very easily. We are using "Root" property of "XDocument" class.
Here is example for this.
In this example we take on "BooksList.xml" file and we display its root element name.
C#. Net Example :
VB.Net Examples :
Output :
Below are the books that you would like :
Here is example for this.
In this example we take on "BooksList.xml" file and we display its root element name.
C#. Net Example :
XElement objRootElement = XDocument.Load(Server.MapPath("BooksList.xml")).Root; Response.Write("<b>Name of root element is : </b>" + objRootElement.Name);
VB.Net Examples :
Dim objRootElement As XElement = XDocument.Load(Server.MapPath("BooksList.xml")).Root Response.Write("<b>Name of root element is : </b>" & objRootElement.Name.ToString())
Output :
Below are the books that you would like :