次の方法で共有


XPathNavigator.SelectDescendants メソッド (XPathNodeType, Boolean)

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

Overloads Public Overridable Function SelectDescendants( _
   ByVal type As XPathNodeType, _   ByVal matchSelf As Boolean _) As XPathNodeIterator
[C#]
public virtual XPathNodeIterator SelectDescendants(XPathNodeTypetype,boolmatchSelf);
[C++]
public: virtual XPathNodeIterator* SelectDescendants(XPathNodeTypetype,boolmatchSelf);
[JScript]
public function SelectDescendants(
   type : XPathNodeType,matchSelf : Boolean) : XPathNodeIterator;

パラメータ

  • type
    子孫ノードの XPathNodeType
  • matchSelf
    選択項目にコンテキスト ノードを含める場合は true 。それ以外の場合は false

戻り値

選択されたノードを指している XPathNodeIterator

解説

このメソッドは、 XPathNavigator 状態には影響を与えません。

子孫は、子、または子の子、以下同様です。したがって、選択したノードには、属性ノードや名前空間ノードが含まれません。

使用例

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

 
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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: 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.SelectDescendants オーバーロードの一覧 | SelectAncestors | SelectChildren | Select