XContainer.Descendants Yöntem

Tanım

Bu belge veya öğe için belge sırasına göre alt öğe koleksiyonunu döndürür.

Aşırı Yüklemeler

Name Description
Descendants()

Bu belge veya öğe için belge sırasına göre alt öğe koleksiyonunu döndürür.

Descendants(XName)

Bu belge veya öğe için, belge sırasına göre alt öğelerden oluşan filtrelenmiş bir koleksiyon döndürür. Yalnızca eşleşen XName öğeler koleksiyona dahil edilir.

Açıklamalar

Bu yöntem ertelenen yürütmeyi kullanır.

Descendants()

Kaynak:
XContainer.cs
Kaynak:
XContainer.cs
Kaynak:
XContainer.cs
Kaynak:
XContainer.cs
Kaynak:
XContainer.cs

Bu belge veya öğe için belge sırasına göre alt öğe koleksiyonunu döndürür.

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)

Döndürülenler

öğesinin IEnumerable<T>XElement alt öğelerini içeren bir XContaineröğesi.

Örnekler

Aşağıdaki örnek bir XML ağacı oluşturur ve alt öğeleri almak için bu eksen yöntemini kullanır.

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

Bu örnek aşağıdaki çıkışı oluşturur:

Child
GrandChild

Açıklamalar

Bu yöntemin elde IEnumerable<T>edilen içinde kendisini döndürmeyeceğini unutmayın. Sonuçlara geçerliyi DescendantsAndSelf eklemeniz gerekip gerekmediğini görünXElement.

Bu yöntem ertelenen yürütmeyi kullanır.

Ayrıca bkz.

Şunlara uygulanır

Descendants(XName)

Kaynak:
XContainer.cs
Kaynak:
XContainer.cs
Kaynak:
XContainer.cs
Kaynak:
XContainer.cs
Kaynak:
XContainer.cs

Bu belge veya öğe için, belge sırasına göre alt öğelerden oluşan filtrelenmiş bir koleksiyon döndürür. Yalnızca eşleşen XName öğeler koleksiyona dahil edilir.

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)

Parametreler

name
XName

Eşleşmesi XName için.

Döndürülenler

IEnumerable<T> XElement Belirtilen XContainerile eşleşen öğesinin alt öğelerini XName içeren bir öğesi.

Örnekler

Aşağıdaki örnek bir öğenin tüm alt öğelerini yazdırır.

// 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

Bu örnek aşağıdaki çıkışı oluşturur:

Child

Aşağıda aynı örnek verilmiştir, ancak bu örnekte XML bir ad alanındadır. Daha fazla bilgi için bkz. XML Ad Alanları ile çalışma.

// 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

Bu örnek aşağıdaki çıkışı oluşturur:

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

Açıklamalar

Bu yöntem ertelenen yürütmeyi kullanır.

Ayrıca bkz.

Şunlara uygulanır