次の方法で共有


XPathNavigator.SelectDescendants メソッド

選択基準と一致する現在のノードのすべての子孫ノードを選択します。

オーバーロードの一覧

XPathNodeType と一致する現在のノードのすべての子孫ノードを選択します。

[Visual Basic] Overloads Public Overridable Function SelectDescendants(XPathNodeType, Boolean) As XPathNodeIterator

[C#] public virtual XPathNodeIterator SelectDescendants(XPathNodeType, bool);

[C++] public: virtual XPathNodeIterator* SelectDescendants(XPathNodeType, bool);

[JScript] public function SelectDescendants(XPathNodeType, Boolean) : XPathNodeIterator;

提供されたローカル名と名前空間 URI を持つ現在のノードのすべての子孫要素ノードを選択します。

[Visual Basic] Overloads Public Overridable Function SelectDescendants(String, String, Boolean) As XPathNodeIterator

[C#] public virtual XPathNodeIterator SelectDescendants(string, string, bool);

[C++] public: virtual XPathNodeIterator* SelectDescendants(String*, String*, bool);

[JScript] public function SelectDescendants(String, String, Boolean) : XPathNodeIterator;

使用例

[Visual Basic, C#, C++] 最初の book 要素に移動し、各テキスト ノードを表示する例を次に示します。

[Visual Basic, C#, C++] メモ   ここでは、SelectDescendants のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Imports System
Imports System.IO
Imports System.Xml.XPath

public class Sample

  public shared sub Main()

    Dim doc as XPathDocument = new XPathDocument("books.xml")
    Dim nav as XPathNavigator = doc.CreateNavigator()
 
    ' Move to the first book node.
    Dim ni as XPathNodeIterator = nav.SelectDescendants("book", "", false)
    ni.MoveNext()
    Dim nav2 as XPathNavigator = ni.Current

    ' Display the content of each element node.
    Dim ni2 as XPathNodeIterator = nav2.SelectDescendants(XPathNodeType.Text, false) 
    while (ni2.MoveNext())
      Console.WriteLine(ni2.Current.Value)
    end while

  end sub
end class

[C#] 
using System;
using System.IO;
using System.Xml.XPath;

public class Sample
{
  public static void Main()
  {
    XPathDocument doc = new XPathDocument("books.xml");
    XPathNavigator nav = doc.CreateNavigator();
 
    // Move to the first book node.
    XPathNodeIterator ni = nav.SelectDescendants("book", "", false);
    ni.MoveNext();
    XPathNavigator nav2 = ni.Current;

    // Display the content of each element node.
    XPathNodeIterator ni2 = nav2.SelectDescendants(XPathNodeType.Text, false); 
    while (ni2.MoveNext()){
      Console.WriteLine(ni2.Current.Value);
    } 

  }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml::XPath;

int main()
{
   XPathDocument* doc = new XPathDocument(S"books.xml");
   XPathNavigator * nav = doc -> CreateNavigator();

   // Move to the first book node.
   XPathNodeIterator * ni = nav -> SelectDescendants(S"book", S"", false);
   ni -> MoveNext();
   XPathNavigator * nav2 = ni -> Current;

   // Display the content of each element node.
   XPathNodeIterator * ni2 = nav2 -> SelectDescendants(XPathNodeType::Text, false); 
   while (ni2 -> MoveNext())
   {
      Console::WriteLine(ni2 -> Current -> Value);
   } 
}

この例では、入力として、 books.xml というファイルを使用しています。

<bookstore>
  <book genre="autobiography" publicationdate="1981" 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" 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" ISBN="1-861001-57-6">
    <title>The Gorgias</title>
    <author>
      <name>Plato</name>
    </author>
    <price>9.99</price>
  </book>
</bookstore>

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

XPathNavigator クラス | XPathNavigator メンバ | System.Xml.XPath 名前空間