See Also: XPathNavigator Members
This class provides an alternative way to access to XML document than World Wide Web Consortium (W3C) standard Document Object Model. XPathNavigator is designed to navigate document based on "XPath data model" (See W3C XPath Recommendation). Unlike System.Xml.XmlNode and System.Xml.XmlDocument, XPathNavigator does not expose its internal tree structure. Instead, this class exposes "current node" information by its properties and methods such as XPathNavigator.LocalName, XPathNavigator.NamespaceURI, XPathNavigator.NodeType, XPathNavigator.GetAttribute and so on. See also System.Xml.XPath.XPathNodeType enumeration that represents all the node types that represents XPathNavigator node type.
With XPathNavigator.Evaluate method, you can evaluate XPath expression against the current node. This method returns object value for the evaluation result that might be either string, number, boolean, node-set or result-tree-fragment. Similarly, XPathNavigator.Select method evaluates argument XPath expression that returns XPath "node set" represented as an System.Xml.XPath.XPathNodeIterator instance.
Attribute nodes can be visited using XPathNavigator.MoveToFirstAttribute or XPathNavigator.MoveToNextAttribute methods. Instead of navigation, attributes values are directly available via XPathNavigator.GetAttribute method.
Namespace nodes can be also visited using XPathNavigator.MoveToFirstNamespace or XPathNavigator.MoveToNextNamespace methods. Note: In terms of XPath, there are three kind of namespace nodes: 1) local namespace declarations, 2) ancestor's namespace declarations that is not overriden by other nearer ancestors, and 3) fixed "xml" prefix that is mapped to "http://www.w3.org/XML/1998/namespace" . Navigation can be filtered using System.Xml.XPath.XPathNamespaceScope.
XPathNavigator is an abstract class and derived classes are provided via System.Xml.XPath.IXPathNavigable. There are two IXPathNavigable implementations in System.Xml.dll: System.Xml.XPath.XPathDocument and System.Xml.XmlDocument. XPathNavigator can be derived by third-party libraries. Also, they don't have to be limited to XML document navigation.
Note: XPathDocument is optimized for navigation, but to create fully-functional XPathNavigator instance that supports XPathNavigator.MoveToId, System.Xml.XmlValidatingReader is required to construct the tree, that means it damages performance. XmlDocument is not optimized for navigation (especially, previous-sibling navigation is much slower than XPathDocument navigator), but it does not require XmlValidatingReader to support ID navigation. It is recommended to choose implementation case by case.