XPathNavigator.SelectAncestors 메서드

정의

선택 조건에 맞는 현재 노드의 상위 노드를 모두 선택합니다.

오버로드

SelectAncestors(XPathNodeType, Boolean)

XPathNodeType이 일치하는 현재 노드의 상위 노드를 모두 선택합니다.

SelectAncestors(String, String, Boolean)

지정된 로컬 이름과 네임스페이스 URI를 사용하는 현재 노드의 상위 노드를 모두 선택합니다.

SelectAncestors(XPathNodeType, Boolean)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

XPathNodeType이 일치하는 현재 노드의 상위 노드를 모두 선택합니다.

public:
 virtual System::Xml::XPath::XPathNodeIterator ^ SelectAncestors(System::Xml::XPath::XPathNodeType type, bool matchSelf);
public virtual System.Xml.XPath.XPathNodeIterator SelectAncestors (System.Xml.XPath.XPathNodeType type, bool matchSelf);
abstract member SelectAncestors : System.Xml.XPath.XPathNodeType * bool -> System.Xml.XPath.XPathNodeIterator
override this.SelectAncestors : System.Xml.XPath.XPathNodeType * bool -> System.Xml.XPath.XPathNodeIterator
Public Overridable Function SelectAncestors (type As XPathNodeType, matchSelf As Boolean) As XPathNodeIterator

매개 변수

type
XPathNodeType

상위 노드의 XPathNodeType입니다.

matchSelf
Boolean

선택할 때 컨텍스트 노드를 포함하려면 true이고, 그러지 않으면 false입니다.

반환

선택된 노드가 포함된 XPathNodeIterator입니다. 반환되는 노드는 문서 순서와 반대로 배치됩니다.

예제

상위 노드를 선택하는 예제는 를 참조하세요 XPathNavigator.SelectAncestors.

설명

메서드는 SelectAncestorsXPathNavigator상태에 영향을 주지 않습니다.

추가 정보

적용 대상

SelectAncestors(String, String, Boolean)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

지정된 로컬 이름과 네임스페이스 URI를 사용하는 현재 노드의 상위 노드를 모두 선택합니다.

public:
 virtual System::Xml::XPath::XPathNodeIterator ^ SelectAncestors(System::String ^ name, System::String ^ namespaceURI, bool matchSelf);
public virtual System.Xml.XPath.XPathNodeIterator SelectAncestors (string name, string namespaceURI, bool matchSelf);
abstract member SelectAncestors : string * string * bool -> System.Xml.XPath.XPathNodeIterator
override this.SelectAncestors : string * string * bool -> System.Xml.XPath.XPathNodeIterator
Public Overridable Function SelectAncestors (name As String, namespaceURI As String, matchSelf As Boolean) As XPathNodeIterator

매개 변수

name
String

상위 노드의 로컬 이름입니다.

namespaceURI
String

상위 노드의 네임스페이스 URI입니다.

matchSelf
Boolean

선택할 때 컨텍스트 노드를 포함하려면 true이고, 그러지 않으면 false입니다.

반환

선택된 노드가 포함된 XPathNodeIterator입니다. 반환되는 노드는 문서 순서와 반대로 배치됩니다.

예외

null을 매개 변수로 전달할 수 없습니다.

예제

다음 예제에서는 상위 노드, 자식 및 하위 노드를 선택하는 것을 보여 줍니다.

XPathDocument^ document = gcnew XPathDocument("contosoBooks.xml");
XPathNavigator^ navigator = document->CreateNavigator();

navigator->MoveToChild("bookstore", "http://www.contoso.com/books");
navigator->MoveToChild("book", "http://www.contoso.com/books");

// Select all the descendant nodes of the book node.
XPathNodeIterator^ bookDescendants = navigator->SelectDescendants("", "http://www.contoso.com/books", false);

// Display the LocalName of each descendant node.
Console::WriteLine("Descendant nodes of the book node:");
while (bookDescendants->MoveNext())
{
    Console::WriteLine(bookDescendants->Current->Name);
}

// Select all the child nodes of the book node.
XPathNodeIterator^ bookChildren = navigator->SelectChildren("", "http://www.contoso.com/books");

// Display the LocalName of each child node.
Console::WriteLine("\nChild nodes of the book node:");
while (bookChildren->MoveNext())
{
    Console::WriteLine(bookChildren->Current->Name);
}

// Select all the ancestor nodes of the title node.
navigator->MoveToChild("title", "http://www.contoso.com/books");

XPathNodeIterator^ bookAncestors = navigator->SelectAncestors("", "http://www.contoso.com/books", false);

// Display the LocalName of each ancestor node.
Console::WriteLine("\nAncestor nodes of the title node:");

while (bookAncestors->MoveNext())
{
    Console::WriteLine(bookAncestors->Current->Name);
}
XPathDocument document = new XPathDocument("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToChild("bookstore", "http://www.contoso.com/books");
navigator.MoveToChild("book", "http://www.contoso.com/books");

// Select all the descendant nodes of the book node.
XPathNodeIterator bookDescendants = navigator.SelectDescendants("", "http://www.contoso.com/books", false);

// Display the LocalName of each descendant node.
Console.WriteLine("Descendant nodes of the book node:");
while (bookDescendants.MoveNext())
{
    Console.WriteLine(bookDescendants.Current.Name);
}

// Select all the child nodes of the book node.
XPathNodeIterator bookChildren = navigator.SelectChildren("", "http://www.contoso.com/books");

// Display the LocalName of each child node.
Console.WriteLine("\nChild nodes of the book node:");
while (bookChildren.MoveNext())
{
    Console.WriteLine(bookChildren.Current.Name);
}

// Select all the ancestor nodes of the title node.
navigator.MoveToChild("title", "http://www.contoso.com/books");

XPathNodeIterator bookAncestors = navigator.SelectAncestors("", "http://www.contoso.com/books", false);

// Display the LocalName of each ancestor node.
Console.WriteLine("\nAncestor nodes of the title node:");

while (bookAncestors.MoveNext())
{
    Console.WriteLine(bookAncestors.Current.Name);
}
Dim document As XPathDocument = New XPathDocument("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToChild("bookstore", "http://www.contoso.com/books")
navigator.MoveToChild("book", "http://www.contoso.com/books")

' Select all the descendant nodes of the book node.
Dim bookDescendants As XPathNodeIterator = navigator.SelectDescendants("", "http://www.contoso.com/books", False)

' Display the LocalName of each descendant node.
Console.WriteLine("Descendant nodes of the book node:")
While bookDescendants.MoveNext()
    Console.WriteLine(bookDescendants.Current.Name)
End While

' Select all the child nodes of the book node.
Dim bookChildren As XPathNodeIterator = navigator.SelectChildren("", "http://www.contoso.com/books")

' Display the LocalName of each child node.
Console.WriteLine(vbCrLf & "Child nodes of the book node:")
While bookChildren.MoveNext()
    Console.WriteLine(bookChildren.Current.Name)
End While

' Select all the ancestor nodes of the title node.
navigator.MoveToChild("title", "http://www.contoso.com/books")

Dim bookAncestors As XPathNodeIterator = navigator.SelectAncestors("", "http://www.contoso.com/books", False)

' Display the LocalName of each ancestor node.
Console.WriteLine(vbCrLf & "Ancestor nodes of the title node:")

While bookAncestors.MoveNext()
    Console.WriteLine(bookAncestors.Current.Name)
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>  

설명

가 매개 변수로 name 지정된 경우 String.Empty 지정된 네임스페이스 URI에 속하는 모든 상위 노드가 선택됩니다. 가 매개 변수로 지정된 경우 String.Empty 네임스페이 namespaceURI 스에 속하지 않는 지정된 로컬 이름을 가진 모든 상위 노드가 선택됩니다. 가 로컬 이름 및 네임스페이스 URI로 모두 지정된 경우 String.Empty 네임스페이스에 속하지 않는 모든 상위 노드가 선택됩니다.

메서드는 SelectAncestorsXPathNavigator상태에 영향을 주지 않습니다.

추가 정보

적용 대상