Share via


Node Set Navigation Using XPathNavigator

Once a set of nodes has been selected, you can navigate in a random access manner over the nodes. Is it important to note that after selecting nodes using Select, you must call MoveNext to position the navigator on the first node that matches the selection criteria. Many of the Move methods described in this section provide navigation over all nodes, except attribute and namespace nodes. To see how to navigate attribute and namespace nodes using XPathNavigator, see Attribute and Namespace Navigation Using XPathNavigator.

The following table shows the navigation methods available, and a description of how they move.

Method Description
MoveTo Moves a navigator to the current position that another given navigator is on. Returns a Boolean indicating success of the move.
MoveToNext Moves the XPathNavigator to the next sibling of the current node.
MoveToPrevious Moves the XPathNavigator to the previous sibling of the current node.
MoveToFirst Moves the XPathNavigator to the first sibling of the current node.
MoveToFirstChild Moves the XPathNavigator to the first child of the current node. This method is valid only on the root node, and node types that have other child nodes. Attribute and namespace nodes are not interpreted as child nodes of element nodes.
MoveToParent Moves the XPathNavigator to the parent of the current node. The root has no parent. All other node types move to the parent or root element.
MoveToRoot Moves the XPathNavigator to the root node that owns this node.
MoveToId Moves the XPathNavigator to the node that has an attribute of type ID, whose value matches the given string.

The movement of methods within a document is done in a top to bottom order. The MoveTo and MoveToId methods do not work on an XmlDataDocument.

See Also

XPathNavigator in the .NET Framework | Node Types Recognized with XPath Queries | Attribute and Namespace Navigation Using XPathNavigator | Compile, Select, Evaluate, and Matches with XPath and XPathExpressions