XPathNavigator navigator = xmlDoc.CreateNavigator(); XPathNavigator node = navigator.Evaluate("/root/element") as XPathNavigator;
XPathNavigator navigator = xmlDoc.CreateNavigator(); XPathNodeIterator nodes = navigator.Evaluate("//element") as XPathNodeIterator; while (nodes.MoveNext()) { XPathNavigator node = nodes.Current; Console.WriteLine(node.Value); }
XPathNavigator navigator = xmlDoc.CreateNavigator(); double sum = (double)navigator.Evaluate("sum(/root/elements/element/@value)");In this example, the XPath expression sum(/root/elements/element/@value) calculates the sum of all value attributes of element nodes that have a parent element named elements, which in turn has a parent element named root. The Evaluate method returns an object that can be cast to the double data type, which represents the calculated sum. Overall, XPathNavigator Evaluate is a powerful tool for manipulating XML data in C#, and it is part of the System.Xml.XPath package library.