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 :
not only tips now onwards write articles..jayeshsorathia,
ReplyDeleteplz increase the tips then last year.
response for my comment.
This is just a line of code but what I used was more than this, actually I used XDocument.Root to get the root element of a document.
ReplyDeleteHi,
DeleteThanks for your valuable comment. "XDocument.Root" return Root XElement object and there are many properties and methods of that object. You can use any of that.