System.Xml.XPath.XPathNodeIterator Class

Provides an iterator over a selected set of nodes.

See Also: XPathNodeIterator Members

Syntax

public abstract class XPathNodeIterator : IEnumerable, ICloneable

Remarks

An System.Xml.XPath.XPathNodeIterator object returned by the System.Xml.XPath.XPathNavigator class is not positioned on the first node in a selected set of nodes. A call to the XPathNodeIterator.MoveNext method of the System.Xml.XPath.XPathNodeIterator class must be made to position the System.Xml.XPath.XPathNodeIterator object on the first node in the selected set of nodes.

When using the System.Xml.XPath.XPathNodeIterator, if you edit the current node or any of its ancestors, your current position is lost. If you want to edit a number of nodes that you have selected, create a System.Xml.XPath.XPathNavigator array, copy all of the nodes from the System.Xml.XPath.XPathNodeIterator into the array, then iterate through the array and modify the nodes.

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 XPathNodeIterator.MoveNext and XPathNodeIterator.Current or use XPathNodeIterator.GetEnumerator. 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