XContainer.Descendants Metodo

Definizione

Restituisce un insieme di elementi discendenti per questo documento o elemento, in ordine di documento.

Overload

Nome Descrizione
Descendants()

Restituisce un insieme di elementi discendenti per questo documento o elemento, in ordine di documento.

Descendants(XName)

Restituisce un insieme filtrato degli elementi discendenti per questo documento o elemento, in ordine di documento. Nella raccolta sono inclusi solo gli elementi con un XName corrispondente.

Commenti

Questo metodo usa l'esecuzione posticipata.

Descendants()

Origine:
XContainer.cs
Origine:
XContainer.cs
Origine:
XContainer.cs
Origine:
XContainer.cs
Origine:
XContainer.cs

Restituisce un insieme di elementi discendenti per questo documento o elemento, in ordine di documento.

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)

Valori restituiti

Oggetto IEnumerable<T> contenente XElement gli elementi discendenti dell'oggetto XContainer.

Esempio

Nell'esempio seguente viene creato un albero XML e quindi viene utilizzato questo metodo dell'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

In questo esempio viene generato l'output seguente:

Child
GrandChild

Commenti

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

Questo metodo usa l'esecuzione posticipata.

Vedi anche

Si applica a

Descendants(XName)

Origine:
XContainer.cs
Origine:
XContainer.cs
Origine:
XContainer.cs
Origine:
XContainer.cs
Origine:
XContainer.cs

Restituisce un insieme filtrato degli elementi discendenti per questo documento o elemento, in ordine di documento. Nella raccolta sono inclusi solo gli elementi con un XName corrispondente.

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 da trovare.

Valori restituiti

Oggetto IEnumerable<T> di XElement contenente gli elementi discendenti dell'oggetto XContainer che corrispondono all'oggetto specificato XName.

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

In questo esempio viene generato 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 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

In questo esempio viene generato l'output seguente:

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

Commenti

Questo metodo usa l'esecuzione posticipata.

Vedi anche

Si applica a