次の方法で共有


XContainer.Descendants メソッド

定義

このドキュメントまたは要素の子孫要素のコレクションをドキュメント順に返します。

オーバーロード

名前 説明
Descendants()

このドキュメントまたは要素の子孫要素のコレクションをドキュメント順に返します。

Descendants(XName)

このドキュメントまたは要素の子孫要素のフィルター処理されたコレクションをドキュメント順に返します。 一致する XName を持つ要素のみがコレクションに含められます。

注釈

このメソッドは遅延実行を使用します。

Descendants()

ソース:
XContainer.cs
ソース:
XContainer.cs
ソース:
XContainer.cs
ソース:
XContainer.cs
ソース:
XContainer.cs

このドキュメントまたは要素の子孫要素のコレクションをドキュメント順に返します。

public:
 System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ Descendants();
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Descendants();
member this.Descendants : unit -> seq<System.Xml.Linq.XElement>
Public Function Descendants () As IEnumerable(Of XElement)

返品

IEnumerable<T> の子孫要素を格納している XElementXContainer

次の例では、XML ツリーを作成し、この軸メソッドを使用して子孫を取得します。

XElement xmlTree = new XElement("Root",
    new XAttribute("Att1", "AttributeContent"),
    new XElement("Child",
        new XText("Some text"),
        new XElement("GrandChild", "element content")
    )
);
IEnumerable<XElement> de =
    from el in xmlTree.Descendants()
    select el;
foreach (XElement el in de)
    Console.WriteLine(el.Name);
' Attributes are not nodes, so will not be returned by DescendantNodes.
Dim xmlTree As XElement = _
    <Root Att1="AttributeContent">
        <Child>Some text
            <GrandChild>element content</GrandChild>
        </Child>
    </Root>
Dim de = From el In xmlTree.Descendants _
         Select el

For Each el In de
    Console.WriteLine(el.Name)
Next

この例を実行すると、次の出力が生成されます。

Child
GrandChild

注釈

このメソッドは、結果として得られる IEnumerable<T>でそれ自体を返さないことに注意してください。 結果に現在XElementの を含める必要があるかどうかを確認DescendantsAndSelfします。

このメソッドは遅延実行を使用します。

こちらもご覧ください

適用対象

Descendants(XName)

ソース:
XContainer.cs
ソース:
XContainer.cs
ソース:
XContainer.cs
ソース:
XContainer.cs
ソース:
XContainer.cs

このドキュメントまたは要素の子孫要素のフィルター処理されたコレクションをドキュメント順に返します。 一致する XName を持つ要素のみがコレクションに含められます。

public:
 System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ Descendants(System::Xml::Linq::XName ^ name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Descendants(System.Xml.Linq.XName name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Descendants(System.Xml.Linq.XName? name);
member this.Descendants : System.Xml.Linq.XName -> seq<System.Xml.Linq.XElement>
Public Function Descendants (name As XName) As IEnumerable(Of XElement)

パラメーター

name
XName

照合する XName

返品

指定した IEnumerable<T> に一致する XElement の子孫要素を格納している XContainerXName

次の例では、 要素のすべての子孫を出力します。

// Attributes are not nodes, so will not be returned by DescendantNodes.
XElement xmlTree = new XElement("Root",
    new XAttribute("Att1", "AttributeContent"),
    new XElement("Child",
        new XText("Some text"),
        new XElement("GrandChild", "element content")
    )
);
IEnumerable<XElement> de =
    from el in xmlTree.Descendants("Child")
    select el;
foreach (XElement el in de)
    Console.WriteLine(el.Name);
' Attributes are not nodes, so will not be returned by the descendants axis.
Dim xmlTree As XElement = _
    <Root Att1="AttributeContent">
         <Child>Some text
             <GrandChild>element content</GrandChild>
         </Child>
     </Root>

Dim de = From el In xmlTree...<Child> _
         Select el

For Each el In de
    Console.WriteLine(el.Name)
Next

この例を実行すると、次の出力が生成されます。

Child

同じ例を次に示しますが、この場合、XML は名前空間内にあります。 詳細については、「 XML 名前空間の操作」を参照してください。

// Attributes are not nodes, so will not be returned by DescendantNodes.
XNamespace aw = "http://www.adventure-works.com";
XElement xmlTree = new XElement(aw + "Root",
    new XAttribute(aw + "Att1", "AttributeContent"),
    new XElement(aw + "Child",
        new XText("Some text"),
        new XElement(aw + "GrandChild", "element content")
    )
);
IEnumerable<XElement> de =
    from el in xmlTree.Descendants(aw + "Child")
    select el;
foreach (XElement el in de)
    Console.WriteLine(el.Name);
Imports <xmlns:aw = "http://www.adventure-works.com">

Module Module1
    Sub Main()
        ' Attributes are not nodes, so will not be returned by the descendants axis.
        Dim xmlTree As XElement = _
            <aw:Root aw:Att1="AttributeContent">
                 <aw:Child>Some text
                     <aw:GrandChild>element content</aw:GrandChild>
                 </aw:Child>
             </aw:Root>

        Dim de = From el In xmlTree...<aw:Child> _
                 Select el

        For Each el In de
            Console.WriteLine(el.Name)
        Next
    End Sub
End Module

この例を実行すると、次の出力が生成されます。

{http://www.adventure-works.com}Child

注釈

このメソッドは遅延実行を使用します。

こちらもご覧ください

適用対象