Searching simple sample for loading a XML document and access a node through XPath expression ?

W

Werner Sammer

I would like to load an XML document from say D:\mytask\mydoc.xml into a CSharp
and to retrieve from the resulting XML node tree a certain node/element by
specifing an XPath expression.

Does someone know a simple CSharp sample source which shows how to implement this task ?

Werner
 
C

Carl Daniel [VC++ MVP]

Werner said:
I would like to load an XML document from say D:\mytask\mydoc.xml
into a CSharp
and to retrieve from the resulting XML node tree a certain
node/element by
specifing an XPath expression.

Does someone know a simple CSharp sample source which shows how to
implement this task ?

using System.Xml;

// ...

XmlDocument xd = new XmlDocument(path-to-your-xml-file);
XmlNode nd = xd.SelectSingleNode("your-xpath-expression");

if (nd != null)
{
// ... do something with the node
}

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top