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

  • Thread starter Thread starter Werner Sammer
  • Start date Start date
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
 
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
 
Back
Top