XPathNavigator.SelectAncestors XPathNavigator.SelectAncestors XPathNavigator.SelectAncestors XPathNavigator.SelectAncestors Method

定義

選択基準と一致する現在のノードのすべての先祖ノードを選択します。Selects all the ancestor nodes of the current node that match the selection criteria.

オーバーロード

SelectAncestors(XPathNodeType, Boolean) SelectAncestors(XPathNodeType, Boolean) SelectAncestors(XPathNodeType, Boolean) SelectAncestors(XPathNodeType, Boolean)

一致する XPathNodeType を持つ現在のノードのすべての先祖ノードを選択します。Selects all the ancestor nodes of the current node that have a matching XPathNodeType.

SelectAncestors(String, String, Boolean) SelectAncestors(String, String, Boolean) SelectAncestors(String, String, Boolean) SelectAncestors(String, String, Boolean)

指定されたローカル名と名前空間 URI を持つ現在のノードのすべての先祖ノードを選択します。Selects all the ancestor nodes of the current node that have the specified local name and namespace URI.

SelectAncestors(XPathNodeType, Boolean) SelectAncestors(XPathNodeType, Boolean) SelectAncestors(XPathNodeType, Boolean) SelectAncestors(XPathNodeType, Boolean)

一致する XPathNodeType を持つ現在のノードのすべての先祖ノードを選択します。Selects all the ancestor nodes of the current node that have a matching 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 XPathNodeType XPathNodeType

先祖ノードの XPathNodeTypeThe XPathNodeType of the ancestor nodes.

matchSelf
Boolean Boolean Boolean Boolean

選択項目にコンテキスト ノードを含める場合は true。それ以外の場合は falseTo include the context node in the selection, true; otherwise, false.

戻り値

選択されたノードを格納している XPathNodeIteratorAn XPathNodeIterator that contains the selected nodes. ノードは、ドキュメントの逆順で返されます。The returned nodes are in reverse document order.

先祖ノードを選択する例についてXPathNavigator.SelectAncestorsは、「」を参照してください。For an example of selecting ancestor nodes, see XPathNavigator.SelectAncestors.

注釈

メソッドは、 XPathNavigatorの状態には影響しません。 SelectAncestorsThe SelectAncestors method has no effect on the state of the XPathNavigator.

こちらもご覧ください

SelectAncestors(String, String, Boolean) SelectAncestors(String, String, Boolean) SelectAncestors(String, String, Boolean) SelectAncestors(String, String, Boolean)

指定されたローカル名と名前空間 URI を持つ現在のノードのすべての先祖ノードを選択します。Selects all the ancestor nodes of the current node that have the specified local name and namespace 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 String String String

先祖ノードのローカル名。The local name of the ancestor nodes.

namespaceURI
String String String String

先祖ノードの名前空間 URI。The namespace URI of the ancestor nodes.

matchSelf
Boolean Boolean Boolean Boolean

選択項目にコンテキスト ノードを含める場合は true。それ以外の場合は falseTo include the context node in the selection, true; otherwise, false.

戻り値

選択されたノードを格納している XPathNodeIteratorAn XPathNodeIterator that contains the selected nodes. ノードは、ドキュメントの逆順で返されます。The returned nodes are in reverse document order.

例外

null はパラメーターとして渡すことはできません。null cannot be passed as a parameter.

次の例では、先祖ノード、子ノード、および子孫ノードを選択する方法を示します。The following example illustrates selecting ancestor, child, and descendant nodes.

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 ファイルを入力として使用します。The example takes the contosoBooks.xml file as an input.

  
<?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してを指定すると、指定した名前空間 URI に属するすべての先祖ノードが選択String.Emptyされます。If String.Empty is specified as the name parameter, all ancestor nodes that belong to the specified namespace URI are selected. String.Empty パラメーターnamespaceURIとして指定されている場合、名前空間に属していない、指定されたローカル名を持つすべての祖先ノードが選択されます。If String.Empty is specified as the namespaceURI parameter, all ancestor nodes with the specified local name that belong to no namespace are selected. String.Emptyローカル名と名前空間 URI の両方として指定されている場合は、名前空間に属していないすべての先祖ノードが選択されます。If String.Empty is specified as both the local name and namespace URI, all ancestor nodes that belong to no namespace are selected.

メソッドは、 XPathNavigatorの状態には影響しません。 SelectAncestorsThe SelectAncestors method has no effect on the state of the XPathNavigator.

こちらもご覧ください

適用対象