XPath in C # code for WPF

You can use XPath if you bind an XML document in XAML, but what if you load an XML document dynamically in code? Are there any XPath methods in C # code?

(using .NET 3.5 SP1)

+3
source share
1 answer

Load the XML into XPathDocument into your code and use XPathNavigator to store the request. Result XPathNavigator.Select () is an iterator that returns the selected nodes.

Example (using System.XML and System.Xml.XPath):

XPathDocument doc = new XPathDocument(@"c:\filepath\doc.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator iter = nav.Select("/xpath/query/here");

while(iter->MoveNext)
{
  //Do something with node here.
}
+3
source

Source: https://habr.com/ru/post/1698586/


All Articles