Mono Class Library: System.Xml.XPath Namespace

System.Xml.XPath.XPathNavigator Class

Provides XPath oriented document navigation feature. [Edit]

See Also: XPathNavigator Members

System.Object
     System.Xml.XPath.XPathItem
          System.Xml.XPath.XPathNavigator

public abstract class XPathNavigator : XPathItem, ICloneable, System.Xml.IXmlNamespaceResolver, IXPathNavigable

Remarks

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.

This class defines some "navigation" methods such as XPathNavigator.MoveToFirstChild and XPathNavigator.MoveToPrevious. They are mainly used in XPath evaluation.

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.

[Edit]

Requirements

Namespace: System.Xml.XPath
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0