Share via


XPathNodeIterator.Current Eigenschaft

Definition

Ruft beim außer Kraft setzen in einer abgeleiteten Klasse das XPathNavigator-Objekt für dieses XPathNodeIterator ab, das im aktuellen Kontextknoten positioniert wurde.

public:
 abstract property System::Xml::XPath::XPathNavigator ^ Current { System::Xml::XPath::XPathNavigator ^ get(); };
public abstract System.Xml.XPath.XPathNavigator? Current { get; }
public abstract System.Xml.XPath.XPathNavigator Current { get; }
member this.Current : System.Xml.XPath.XPathNavigator
Public MustOverride ReadOnly Property Current As XPathNavigator

Eigenschaftswert

XPathNavigator

Ein im Kontextknoten positioniertes XPathNavigator-Objekt, von dem aus die Knotengruppe ausgewählt wurde. Die MoveNext()-Methode muss aufgerufen werden, um XPathNodeIterator auf den ersten Knoten in der ausgewählten Gruppe zu verschieben.

Beispiele

Im folgenden Beispiel werden alle Buchtitel, die von Herman Melville erstellt wurden, mithilfe der Current Eigenschaft des XPathNodeIterator Objekts und der Clone Methode der XPathNavigator Klasse abgerechnet.

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);
}
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);
}
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

In diesem Beispiel wird die Datei contosoBooks.xml als Eingabe verwendet.

<?xml version="1.0" encoding="utf-8" ?>  
<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>  

Hinweise

Sie können die Eigenschaften des zurückgegebenen XPathNavigator Objekts verwenden, um Informationen zum aktuellen Knoten abzurufen. Das zurückgegebene XPathNavigator Objekt sollte jedoch nicht geändert werden. Das zurückgegebene XPathNavigator Objekt kann nicht vom ausgewählten Knotensatz entfernt werden.

Alternativ können Sie das XPathNavigator Objekt mithilfe der Clone Methode der XPathNavigator Klasse klonen. Das geklonte XPathNavigator Objekt kann dann vom ausgewählten Knotensatz entfernt werden. Diese Methode zum Klonen des XPathNavigator Objekts kann sich auf die Leistung der XPath-Abfrage auswirken.

Wenn die SelectAncestors, SelectDescendantsund SelectChildren Methoden dazu führen, dass keine Knoten ausgewählt werden, zeigt die Current Eigenschaft möglicherweise nicht auf den Kontextknoten.

Um zu testen, ob Knoten ausgewählt wurden, verwenden Sie die Count Eigenschaft wie im folgenden Beispiel dargestellt.

Gilt für

Siehe auch