Namespace:
System.Xml.XPath
Assembly:
System.Xml (in System.Xml.dll)
Visual Basic (Declaration)
Public MustOverride ReadOnly Property Current As XPathNavigator
Dim instance As XPathNodeIterator
Dim value As XPathNavigator
value = instance.Current
public abstract XPathNavigator Current { get; }
public:
virtual property XPathNavigator^ Current {
XPathNavigator^ get () abstract;
}
public abstract function get Current () : XPathNavigator
You can use the properties of the returned XPathNavigator object to obtain information on the current node. However, the returned XPathNavigator object should not be modified. The returned XPathNavigator object cannot be moved away from the selected node set.
Alternatively, you can clone the XPathNavigator object using the Clone method of the XPathNavigator class. The cloned XPathNavigator object can then be moved away from the selected node set. This method of cloning the XPathNavigator object might affect the performance of the XPath query.
If the SelectAncestors, SelectDescendants, and SelectChildren methods result in no nodes being selected, the Current property might not be pointing to the context node.
To test whether nodes have been selected, use the Count property as shown in the following example.
The following example gets all book titles authored by Herman Melville using the Current property of the XPathNodeIterator object and the Clone method of the XPathNavigator class.
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()
' Select all books authored by Melville.
Dim nodes As XPathNodeIterator = navigator.Select("descendant::book[author/last-name='Melville']")
While nodes.MoveNext()
' Clone the navigator returned by the Current property.
' Use the cloned navigator to get the title element.
Dim clone As XPathNavigator = nodes.Current.Clone()
clone.MoveToFirstChild()
Console.WriteLine("Book title: {0}", clone.Value)
End While
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();
// Select all books authored by Melville.
XPathNodeIterator nodes = navigator.Select("descendant::book[author/last-name='Melville']");
while (nodes.MoveNext())
{
// Clone the navigator returned by the Current property.
// Use the cloned navigator to get the title element.
XPathNavigator clone = nodes.Current.Clone();
clone.MoveToFirstChild();
Console.WriteLine("Book title: {0}", clone.Value);
}
XPathDocument^ document = gcnew XPathDocument("books.xml");
XPathNavigator^ navigator = document->CreateNavigator();
// Select all books authored by Melville.
XPathNodeIterator^ nodes = navigator->Select("descendant::book[author/last-name='Melville']");
while (nodes->MoveNext())
{
// Clone the navigator returned by the Current property.
// Use the cloned navigator to get the title element.
XPathNavigator^ clone = nodes->Current->Clone();
clone->MoveToFirstChild();
Console::WriteLine("Book title: {0}", clone->Value);
}
The example takes the contosoBooks.xml file as input.
<bookstore xmlns="http://www.contoso.com/books">
<book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Reference