XContainer.Descendants Metodo
Definizione
Restituisce una raccolta di elementi discendenti del documento o elemento nell'ordine dei documenti.Returns a collection of the descendant elements for this document or element, in document order.
Overload
Descendants() |
Restituisce una raccolta di elementi discendenti del documento o elemento nell'ordine dei documenti.Returns a collection of the descendant elements for this document or element, in document order. |
Descendants(XName) |
Restituisce una raccolta filtrata degli elementi discendenti di questo documento o elemento nell'ordine dei documenti.Returns a filtered collection of the descendant elements for this document or element, in document order. Solo gli elementi che hanno un oggetto XName corrispondente vengono inclusi nella raccolta.Only elements that have a matching XName are included in the collection. |
Commenti
Questo metodo utilizza l'esecuzione posticipata.This method uses deferred execution.
Descendants()
Restituisce una raccolta di elementi discendenti del documento o elemento nell'ordine dei documenti.Returns a collection of the descendant elements for this document or element, in document order.
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.An IEnumerable<T> of XElement containing the descendant elements of the XContainer.
Esempi
Nell'esempio seguente viene creato un albero XML, quindi viene utilizzato il metodo dell'asse per recuperare i discendenti.The following example creates an XML tree, and then uses this axis method to retrieve the descendants.
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
Questo esempio produce il seguente output:This example produces the following output:
Child
GrandChild
Commenti
Si noti che questo metodo non restituirà se stesso nell' IEnumerable<T>oggetto risultante.Note that this method will not return itself in the resulting IEnumerable<T>. Verificare DescendantsAndSelf se è necessario includere l'oggetto corrente XElement nei risultati.See DescendantsAndSelf if you need to include the current XElement in the results.
Questo metodo utilizza l'esecuzione posticipata.This method uses deferred execution.
Vedi anche
Descendants(XName)
Restituisce una raccolta filtrata degli elementi discendenti di questo documento o elemento nell'ordine dei documenti.Returns a filtered collection of the descendant elements for this document or element, in document order. Solo gli elementi che hanno un oggetto XName corrispondente vengono inclusi nella raccolta.Only elements that have a matching XName are included in the collection.
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
Restituisce
IEnumerable<T> di XElement contenente gli elementi discendenti del XContainer che corrispondono al XName specificato.An IEnumerable<T> of XElement containing the descendant elements of the XContainer that match the specified XName.
Esempi
Nell'esempio seguente vengono stampati tutti i discendenti di un elemento.The following example prints all descendants of an element.
// 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
Questo esempio produce il seguente output:This example produces the following output:
Child
Di seguito è riportato lo stesso esempio, ma in questo caso il codice XML si trova in uno spazio dei nomi.The following is the same example, but in this case the XML is in a namespace. Per ulteriori informazioni, vedere utilizzo degli spazi dei nomi XML.For more information, see Working with XML Namespaces.
// 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
Questo esempio produce il seguente output:This example produces the following output:
{http://www.adventure-works.com}Child
Commenti
Questo metodo utilizza l'esecuzione posticipata.This method uses deferred execution.