XContainer.Descendants Metoda

Definicja

Zwraca kolekcję elementów podrzędnych dla tego dokumentu lub elementu w kolejności dokumentu.

Przeciążenia

Descendants()

Zwraca kolekcję elementów podrzędnych dla tego dokumentu lub elementu w kolejności dokumentu.

Descendants(XName)

Zwraca odfiltrowaną kolekcję elementów podrzędnych dla tego dokumentu lub elementu w kolejności dokumentu. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName .

Uwagi

Ta metoda używa odroczonego wykonania.

Descendants()

Źródło:
XContainer.cs
Źródło:
XContainer.cs
Źródło:
XContainer.cs

Zwraca kolekcję elementów podrzędnych dla tego dokumentu lub elementu w kolejności dokumentu.

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)

Zwraca

XElement Element IEnumerable<T> zawierający elementy podrzędne elementu XContainer.

Przykłady

Poniższy przykład tworzy drzewo XML, a następnie używa tej metody osi do pobierania elementów potomnych.

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  

Ten przykład generuje następujące wyniki:

Child  
GrandChild  

Uwagi

Należy pamiętać, że ta metoda nie zwróci się w wynikowej IEnumerable<T>metodzie . Sprawdź DescendantsAndSelf , czy musisz uwzględnić bieżący element XElement w wynikach.

Ta metoda używa odroczonego wykonania.

Zobacz też

Dotyczy

Descendants(XName)

Źródło:
XContainer.cs
Źródło:
XContainer.cs
Źródło:
XContainer.cs

Zwraca odfiltrowaną kolekcję elementów podrzędnych dla tego dokumentu lub elementu w kolejności dokumentu. W kolekcji znajdują się tylko elementy, które mają dopasowanie 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)

Parametry

name
XName

Element XName do dopasowania.

Zwraca

XElement Element IEnumerable<T> zawierający elementy podrzędne elementu XContainer zgodnego z określonym XNameelementem .

Przykłady

Poniższy przykład wyświetla wszystkie elementy podrzędne elementu.

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

Ten przykład generuje następujące wyniki:

Child  

Poniżej przedstawiono ten sam przykład, ale w tym przypadku kod XML znajduje się w przestrzeni nazw. Aby uzyskać więcej informacji, zobacz Praca z przestrzeniami nazw 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  

Ten przykład generuje następujące wyniki:

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

Uwagi

Ta metoda używa odroczonego wykonania.

Zobacz też

Dotyczy