XContainer.DescendantNodes Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Restituisce un insieme dei nodi discendenti per questo documento o elemento, in ordine di documento.
public:
System::Collections::Generic::IEnumerable<System::Xml::Linq::XNode ^> ^ DescendantNodes();
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XNode> DescendantNodes();
member this.DescendantNodes : unit -> seq<System.Xml.Linq.XNode>
Public Function DescendantNodes () As IEnumerable(Of XNode)
Valori restituiti
Oggetto IEnumerable<T> contenente XNode i nodi discendenti di , in ordine di XContainerdocumento.
Esempio
L'esempio seguente crea un albero XML e quindi scorre l'asse DescendantNodes .
XElement xmlTree = new XElement("Root",
// Attributes are not nodes, so will not be returned by DescendantNodes.
new XAttribute("Att1", "AttributeContent"),
new XElement("Child",
new XElement("GrandChild", "element content")
)
);
IEnumerable<XNode> dnas =
from node in xmlTree.DescendantNodes()
select node;
foreach (XNode node in dnas)
{
if (node is XElement)
Console.WriteLine((node as XElement).Name);
else
Console.WriteLine(node);
}
' Attributes are not nodes, so will not be returned by DescendantNodes.
Dim xmlTree As XElement = _
<Root Att1="AttributeContent">
<Child>
<GrandChild>element content</GrandChild>
</Child>
</Root>
Dim dnas = From node In xmlTree.DescendantNodes _
Select node
For Each node In dnas
If TypeOf node Is XElement Then
Console.WriteLine(DirectCast(node, XElement).Name)
Else
Console.WriteLine(node)
End If
Next
In questo esempio viene generato l'output seguente:
Child
GrandChild
element content
Commenti
Si noti che gli attributi non sono considerati nodi in LINQ to XML, quindi non faranno parte della raccolta restituita da questo metodo.
Questo metodo usa l'esecuzione posticipata.