XPathNodeIterator.Current 속성

정의

파생 클래스에서 재정의된 경우 현재 컨텍스트 노드에 위치한 이 XPathNavigator에 대한 XPathNodeIterator 개체를 가져옵니다.

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

속성 값

XPathNavigator

노드 집합을 선택한 컨텍스트 노드로 위치가 지정된 XPathNavigator 개체입니다. MoveNext() 메서드를 호출하여 XPathNodeIterator를 선택된 집합의 첫 번째 노드로 이동해야 합니다.

예제

다음 예제에서는 개체의 속성과 Clone 클래스의 XPathNodeIterator 메서드를 사용하여 Current Herman Melville이 작성한 모든 책 제목을 XPathNavigator 가져옵니다.

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

이 예제에서는 contosoBooks.xml 파일을 입력으로 사용합니다.

<?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>  

설명

반환 XPathNavigator 된 개체의 속성을 사용하여 현재 노드에 대한 정보를 가져올 수 있습니다. 그러나 반환 XPathNavigator 된 개체는 수정하면 안 됩니다. 반환된 XPathNavigator 개체를 선택한 노드 집합에서 멀리 이동할 수 없습니다.

또는 클래스의 메서드를 XPathNavigator 사용하여 개체를 복제할 Clone XPathNavigator 수 있습니다. 그러면 복제된 XPathNavigator 개체를 선택한 노드 집합에서 멀리 이동할 수 있습니다. 개체를 복제하는 XPathNavigator 이 방법은 XPath 쿼리의 성능에 영향을 줄 수 있습니다.

SelectDescendantsSelectChildren 메서드로 SelectAncestors인해 노드가 선택되지 않으면 속성이 Current 컨텍스트 노드를 가리키지 않을 수 있습니다.

노드가 선택되었는지 여부를 테스트하려면 다음 예제와 같이 속성을 사용합니다 Count .

적용 대상

추가 정보