XElement.DescendantNodesAndSelf Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Devolve uma coleção de nós que contêm este elemento, e todos os nós descendentes deste elemento, por ordem de documento.
public:
System::Collections::Generic::IEnumerable<System::Xml::Linq::XNode ^> ^ DescendantNodesAndSelf();
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XNode> DescendantNodesAndSelf();
member this.DescendantNodesAndSelf : unit -> seq<System.Xml.Linq.XNode>
Public Function DescendantNodesAndSelf () As IEnumerable(Of XNode)
Devoluções
An IEnumerable<T> de XNode que contêm este elemento, e todos os nós descendentes deste elemento, por ordem de documento.
Exemplos
O exemplo seguinte cria uma árvore XML e depois usa esta .
XElement xmlTree = new XElement("Root",
// Attributes are not nodes, so will not be returned by DescendantNodesAndSelf.
new XAttribute("Att1", "AttributeContent"),
new XElement("Child",
new XText("Some text"),
new XElement("GrandChild", "element content")
)
);
IEnumerable<XNode> dnas =
from node in xmlTree.DescendantNodesAndSelf()
select node;
foreach (XNode node in dnas)
{
if (node is XElement)
Console.WriteLine((node as XElement).Name);
else
Console.WriteLine(node);
}
Dim xmlTree As XElement = _
<Root Att1="AttributeContent">
<Child>Some text<GrandChild>element content</GrandChild>
</Child>
</Root>
Dim dnas As IEnumerable(Of XNode) = _
From node In xmlTree.DescendantNodesAndSelf() _
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
Este exemplo produz a seguinte saída:
Root
Child
Some text
GrandChild
element content
Observações
Este método utiliza execução diferida.