XContainer.Descendants Metodo

Definizione

Restituisce una raccolta di elementi discendenti del documento o elemento nell'ordine dei documenti.

Overload

Descendants()

Restituisce una raccolta di elementi discendenti del documento o elemento nell'ordine dei documenti.

Descendants(XName)

Restituisce una raccolta filtrata degli elementi discendenti di questo documento o elemento nell'ordine dei documenti. Solo gli elementi che hanno un oggetto XName corrispondente vengono inclusi nella raccolta.

Commenti

Questo metodo usa l'esecuzione posticipata.

Descendants()

Source:
XContainer.cs
Source:
XContainer.cs
Source:
XContainer.cs

Restituisce una raccolta di elementi discendenti del documento o elemento nell'ordine dei documenti.

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)

Restituisce

IEnumerable<T> di XElement che contiene gli elementi discendenti del XContainer.

Esempio

L'esempio seguente crea un albero XML e quindi usa questo metodo asse per recuperare i discendenti.

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  

Nell'esempio viene prodotto l'output seguente:

Child  
GrandChild  

Commenti

Si noti che questo metodo non restituirà se stesso nell'oggetto risultante IEnumerable<T>. Vedere DescendantsAndSelf se è necessario includere l'oggetto corrente XElement nei risultati.

Questo metodo usa l'esecuzione posticipata.

Vedi anche

Si applica a

Descendants(XName)

Source:
XContainer.cs
Source:
XContainer.cs
Source:
XContainer.cs

Restituisce una raccolta filtrata degli elementi discendenti di questo documento o elemento nell'ordine dei documenti. Solo gli elementi che hanno un oggetto XName corrispondente vengono inclusi nella raccolta.

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)

Parametri

name
XName

Oggetto XName di cui trovare la corrispondenza.

Restituisce

IEnumerable<T> di XElement contenente gli elementi discendenti del XContainer che corrispondono al XName specificato.

Esempio

Nell'esempio seguente vengono stampati tutti i discendenti di un elemento.

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

Nell'esempio viene prodotto l'output seguente:

Child  

Di seguito è riportato lo stesso esempio, ma in questo caso il codice XML si trova in uno spazio dei nomi. Per altre informazioni, vedere Usare gli spazi dei nomi 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  

Nell'esempio viene prodotto l'output seguente:

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

Commenti

Questo metodo usa l'esecuzione posticipata.

Vedi anche

Si applica a