다음을 통해 공유


XPathNodeIterator.Current 속성

파생 클래스에서 재정의된 경우 이 XPathNodeIterator에 대한 XPathNavigator 개체를 현재 컨텍스트 노드에 위치된 상태로 반환합니다.

네임스페이스: System.Xml.XPath
어셈블리: System.Xml(system.xml.dll)

구문

‘선언
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;
}
/** @property */
public abstract XPathNavigator get_Current ()
public abstract function get Current () : XPathNavigator

속성 값

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

설명

반환된 XPathNavigator 개체의 속성을 사용하여 현재 노드에 관한 정보를 얻을 수 있습니다. 그러나 반환된 XPathNavigator 개체는 수정할 수 없습니다. 반환된 XPathNavigator 개체는 선택된 노드 집합 밖으로 이동할 수 없습니다.

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

SelectAncestors, SelectDescendantsSelectChildren 메서드를 실행한 결과 아무 노드도 선택되지 않은 경우 Current 속성이 컨텍스트 노드를 가리키고 있지 않을 수도 있습니다.

선택된 노드가 있는지 확인하려면 다음 예제와 같이 Count 속성을 사용합니다.

예제

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

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();
XPathExpression^ query = 
    navigator->Compile("/bookstore/book");
XPathNodeIterator^ nodes = navigator->Select(query);
XPathNavigator^ nodesNavigator = nodes->Current;
for each(XPathNavigator^ navigator in nodesNavigator->
    SelectDescendants(XPathNodeType::Text, false))
{
    Console::Write(navigator->Name);
    Console::WriteLine(navigator->Value);
}

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

<bookstore xmlns="https://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 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

XPathNodeIterator 클래스
XPathNodeIterator 멤버
System.Xml.XPath 네임스페이스
MoveNext
Clone
SelectAncestors
SelectDescendants
SelectChildren
XPathNodeIterator.Count 속성