提供されたローカル名と名前空間 URI を持つ現在のノードのすべての祖先要素ノードを選択します。
Overloads Public Overridable Function SelectAncestors( _
ByVal name As String, _ ByVal namespaceURI As String, _ ByVal matchSelf As Boolean _) As XPathNodeIterator
[C#]
public virtual XPathNodeIterator SelectAncestors(stringname,stringnamespaceURI,boolmatchSelf);
[C++]
public: virtual XPathNodeIterator* SelectAncestors(String* name,String* namespaceURI,boolmatchSelf);
[JScript]
public function SelectAncestors(
name : String,namespaceURI : String,matchSelf : Boolean) : XPathNodeIterator;
パラメータ
- name
祖先ノードのローカル名。 - namespaceURI
祖先ノードの名前空間 URI。 - matchSelf
選択項目にコンテキスト ノードを含める場合は true 。それ以外の場合は false 。
戻り値
選択されたノードを指している XPathNodeIterator 。ノードは、ドキュメントの逆順で返されます。
解説
このメソッドは、 XPathNavigator 状態には影響を与えません。
name が空の文字列の場合は、指定した名前空間 URI に属するすべての祖先ノードが選択されます。 namespaceURI が空の文字列の場合は、null 名前空間に属する指定した名前を持つすべての祖先ノードが選択されます。name および namespaceURI の両方が空の文字列の場合は、null 名前空間に属するすべての祖先ノードが選択されます。
使用例
[Visual Basic, C#, C++] 指定した CD を含むすべての注文を選択する例を次に示します。
Imports System
Imports System.Xml.XPath
public class Sample
public shared sub Main()
Dim doc as XPathDocument = new XPathDocument("order.xml")
Dim nav as XPathNavigator = doc.CreateNavigator()
' Select all cd nodes with the specified ISBN value.
Dim ni as XPathNodeIterator = nav.Select("//cd[@ISBN='2-3631-4']")
' Select all orders containing the selected cd node.
while (ni.MoveNext())
Dim nav2 as XPathNavigator = ni.Current
Dim ni2 as XPathNodeIterator = nav2.SelectAncestors("order", "", false)
while (ni2.MoveNext())
Console.WriteLine(ni2.Current.ToString())
end while
end while
end sub
end class
[C#]
using System;
using System.Xml.XPath;
public class Sample
{
public static void Main()
{
XPathDocument doc = new XPathDocument("order.xml");
XPathNavigator nav = doc.CreateNavigator();
// Select all cd nodes with the specified ISBN value.
XPathNodeIterator ni = nav.Select("//cd[@ISBN='2-3631-4']");
// Select all orders containing the selected cd node.
while (ni.MoveNext()){
XPathNavigator nav2 = ni.Current;
XPathNodeIterator ni2 = nav2.SelectAncestors("order", "", false);
while (ni2.MoveNext())
Console.WriteLine(ni2.Current.ToString());
}
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml::XPath;
int main()
{
XPathDocument* doc = new XPathDocument(S"order.xml");
XPathNavigator * nav = doc -> CreateNavigator();
// Select all cd nodes with the specified ISBN value.
XPathNodeIterator * ni = nav -> Select(S"//cd[@ISBN='2-3631-4']");
// Select all orders containing the selected cd node.
while (ni -> MoveNext())
{
XPathNavigator * nav2 = ni -> Current;
XPathNodeIterator * ni2 = nav2 -> SelectAncestors(S"order", S"", false);
while (ni2 -> MoveNext())
Console::WriteLine(ni2 -> Current);
}
}
この例では、入力として、 order.xml というファイルを使用しています。
<!--Represents a customer order-->
<order>
<book ISBN='10-861003-324'>
<title>The Handmaid's Tale</title>
<price>19.95</price>
</book>
<cd ISBN='2-3631-4'>
<title>Americana</title>
<price>16.95</price>
</cd>
</order>
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
XPathNavigator クラス | XPathNavigator メンバ | System.Xml.XPath 名前空間 | XPathNavigator.SelectAncestors オーバーロードの一覧 | SelectChildren | SelectDescendants | Select