We help IT Professionals succeed at work.

How to get a XML node by name

starusa
starusa asked
on
Hello,

I'd like to know how to get a XML node text using its name in ASP.NET, somehow like the javascript getElementById.

Thank you.
Comment
Watch Question

Commented:
You can use XPath to get the Node or list of nodes with the name that you want.

Sample if you have a XmlNode object with a couple of childnodes:
<data>
    <data1></data1>
    <data2></data2>
</data>

XmlDocument xd = new XmlDocument().Load("xml_file");
XmlNode xmlNode = xd.SelectSingleNode("/data");

if you want to get the data1 node you'd do something like this:
xmlNode.SelectSingleNode("./data1");

Explore More ContentExplore courses, solutions, and other research materials related to this topic.