Export (0) Print
Expand All

XPathNodeIterator.Current Property

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

[Visual Basic]
Public MustOverride ReadOnly Property Current As XPathNavigator
[C#]
public abstract XPathNavigator Current {get;}
[C++]
public: __property virtual XPathNavigator* get_Current() = 0;
[JScript]
public abstract function get Current() : XPathNavigator;

Property Value

An XPathNavigator positioned on the current node.

Note The XPathNodeIterator is initially positioned on the context node from which the node set was selected. MoveNext must be called to move the XPathNodeIterator to the first node in the selected set.

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 "data.xml" which was loaded by the XPath engine into an XPathDocument object. Because these are two different data stores (XmlDocument and XPathDocument), the 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(/"data.xml/")");
while (Iterator.MoveNext())
  Console.WriteLine(typeof(Iterator.Current));

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

Example

See AddSort (in the XPathExpression class) for an example using this property.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

XPathNodeIterator Class | XPathNodeIterator Members | System.Xml.XPath Namespace | CurrentPosition | XPathNavigator.MoveTo | XPathNavigator.Clone

Show:
© 2015 Microsoft