Accessing particular node/element in XML file


Accessing particular node/element in XML file

Accessing particular node/element in XML file



XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("employee.xml"));
XmlNodeList nodelist = doc.DocumentElement.SelectNodes("emp/name");
int n = nodelist.Count;

for (int i = 0; i < n; i++)
{
Label1.Text += nodelist[i].InnerText +"
";
}



Explanation:

The code snippet demonstrates how to access a particular node/element in xml.
Using XmlDocument object load XML file. Using XmlNodeList object access the particular node by
doc.DocumentElement.SelectSingleNode("ParentElemenetName/ElementName")
Iterate through data of nodes and retrieve data


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: