System.Xml.XPath.XPathNodeIterator.MoveNext Method

When overridden in a derived class, moves the System.Xml.XPath.XPathNavigator object returned by the XPathNodeIterator.Current property to the next node in the selected node set.

Syntax

public abstract bool MoveNext ()

Returns

true if the System.Xml.XPath.XPathNavigator object moved to the next node; false if there are no more selected nodes.

Remarks

The System.Xml.XPath.XPathNodeIterator object is positioned on the first node in the selected node set only after the initial call to the XPathNodeIterator.MoveNext method. The node set is created in document order. Therefore, calling the XPathNodeIterator.MoveNext method moves to the next node in document order.

There are two ways to iterate over an System.Xml.XPath.XPathNavigator collection by using the System.Xml.XPath.XPathNodeIterator class.

One way is to use the XPathNodeIterator.MoveNext method and then call XPathNodeIterator.Current to get the current System.Xml.XPath.XPathNavigator instance, as in the following example:

code reference: XPathNavigatorMethods#55

Another way is to use a foreach loop to call the XPathNodeIterator.GetEnumerator method and use the returned IEnumerator interface to enumerate the nodes, as in the following example:

code reference: XPathNavigatorMethods#56

You should either use the XPathNodeIterator.MoveNext method and XPathNodeIterator.Current or use the XPathNodeIterator.GetEnumerator method. Combining these two approaches can cause unexpected results. For example, if the XPathNodeIterator.MoveNext method is called first, and then the XPathNodeIterator.GetEnumerator method is called in the foreach loop, the foreach loop will not start enumerating the results from the beginning of the collection, but from the position after the XPathNodeIterator.Current method.

Requirements

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