System.Xml.XPath.XPathNodeIterator Class

Assembly: System.Xml.dll
Namespace: System.Xml.XPath
Summary
Provides an iterator over a set of selected nodes.
C# Syntax:
public abstract class XPathNodeIterator : ICloneable
See also:
System.Xml.XPath Namespace

System.Xml.XPath.XPathNodeIterator Member List:

Public Properties
Count Read-only

Gets the index of the last node in the selected set of nodes.
Current Read-only

When overridden in a derived class, returns the navigator for this XPathNodeIterator positioned on the current node.
CurrentPosition Read-only

When overridden in a derived class, gets the index of the current position in the selected set of nodes.
Public Methods
Clone When overridden in a derived class, creates a new XPathNodeIterator.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
MoveNext When overridden in a derived class, moves the XPathNavigator to the next node in the selected set.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Xml.XPath.XPathNodeIterator Member Details

ctor #1
Summary:
Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
protected XPathNodeIterator();

Return to top


Property: Count (read-only)
Summary
Gets the index of the last node in the selected set of nodes.
C# Syntax:
public virtual int Count {get;}
Remarks
The Count property clones the XPathNodeIterator and walks the node set. As a result, there can be some performance loss depending on the number of items in the node set.

The Count property does not effect the current position of the XPathNodeIterator.

Return to top


Property: Current (read-only)
Summary
When overridden in a derived class, returns the navigator for this XPathNodeIterator positioned on the current node.
C# Syntax:
public abstract XPathNavigator Current {get;}
Remarks
You can use the properties of the XPathNavigator to return information on the current node. However, the XPathNavigator cannot be used to move away from the selected node set. Doing so could invalidate the state of the navigator. Alternatively, you can clone the XPathNavigator. The cloned XPathNavigator can then be moved away from the selected node set. This is an application level decision. Providing this functionality may effect the performance of the XPath query.

Although in the majority of cases the same XPathNavigator is returned for all nodes in the selected node set, this is not guaranteed. In the following example, the resultant node set is a combination of the nodes from the loaded document, "Myfile.xml", and "bar.xml" which was loaded by the XPath engine into an XPathDocument object. Because these are two different data stores ( XmlDocument and XPathDocument), the IXPathNavigable.CreateNavigator method hands out different implementations of the XPathNavigator. Hence, the typeof call will indicate different implementations of the XPathNavigator.Note: This could also occur when passing an XPathNodeIterator to an <msxsl:script> function.

              XPathDocument Doc = new XPathDocument("Myfile.xml");
              XPathNavigator Nav =  Doc.CreateNavigator();
              XPathNodeIterator Iterator = Nav.Select("child::* | document(/"bar.xml/")");
              while (Iterator.MoveNext())
                Console.WriteLine(typeof(Iterator.Current));
            

If the XPathNavigator.SelectAncestors, XPathNavigator.SelectDescendants and XPathNavigator.SelectChildren methods result in no nodes being selected it is not guaranteed that Current is pointing to the context node.

Example
See XPathExpression.AddSort (in the XPathExpression class) for an example using this property.
See also:
XPathNodeIterator.CurrentPosition | XPathNavigator.MoveTo | XPathNavigator.Clone

Return to top


Property: CurrentPosition (read-only)
Summary
When overridden in a derived class, gets the index of the current position in the selected set of nodes.
C# Syntax:
public abstract int CurrentPosition {get;}
Remarks

Return to top


Method: Clone()
Summary
When overridden in a derived class, creates a new XPathNodeIterator.
C# Syntax:
public abstract XPathNodeIterator Clone();
Return Value:
A new XPathNodeIterator object.
Remarks
The cloned XPathNodeIterator is not effected by subsequent changes to the current XPathNodeIterator.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~XPathNodeIterator();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MoveNext()
Summary
When overridden in a derived class, moves the XPathNavigator to the next node in the selected set.
C# Syntax:
public abstract bool MoveNext();
Return Value:
true if the XPathNavigator moved to the next node; false if there are no more selected nodes.
Remarks
The node set is created in document order, therefore calling this method moves to the next node in document order. The XPathNodeIterator is positioned on the first node in the selected set after the initial call to MoveNext. This makes it easy to write a while loop.
              XPathDocument doc = new XPathDocument("data.xml");
              XPathNavigator nav = doc.CreateNavigator();
              XPathNodeIterator iterator = nav.Select("/bookstore/book[3]");
              while (iterator.MoveNext()){
                Console.WriteLine(iterator.Current.Name);
              }
                 
            
Example
See XPathExpression.SetContext (in the XPathExpression class) for an example using this method.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.