XContainer.Descendants 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 dos elementos descendentes deste documento ou elemento, por ordem do documento.
Sobrecargas
| Name | Description |
|---|---|
| Descendants() |
Devolve uma coleção dos elementos descendentes deste documento ou elemento, por ordem do documento. |
| Descendants(XName) |
Devolve uma coleção filtrada dos elementos descendentes deste documento ou elemento, por ordem do documento. Apenas os elementos que têm correspondência XName são incluídos na coleção. |
Observações
Este método utiliza execução diferida.
Descendants()
- Origem:
- XContainer.cs
- Origem:
- XContainer.cs
- Origem:
- XContainer.cs
- Origem:
- XContainer.cs
- Origem:
- XContainer.cs
Devolve uma coleção dos elementos descendentes deste documento ou elemento, por ordem do 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)
Devoluções
Um IEnumerable<T> de XElement contendo os elementos descendentes do XContainer.
Exemplos
O exemplo seguinte cria uma árvore XML e depois utiliza este método de eixo para recuperar os descendentes.
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
Este exemplo produz a seguinte saída:
Child
GrandChild
Observações
Note que este método não se devolverá a si próprio no resultado IEnumerable<T>. Vê DescendantsAndSelf se precisas de incluir a corrente XElement nos resultados.
Este método utiliza execução diferida.
Ver também
Aplica-se a
Descendants(XName)
- Origem:
- XContainer.cs
- Origem:
- XContainer.cs
- Origem:
- XContainer.cs
- Origem:
- XContainer.cs
- Origem:
- XContainer.cs
Devolve uma coleção filtrada dos elementos descendentes deste documento ou elemento, por ordem do documento. Apenas os elementos que têm correspondência XName são incluídos na coleção.
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)
Parâmetros
Devoluções
Um de IEnumerable<T> contendo os elementos descendentes de os XElement que correspondem XContainer ao especificado XName.
Exemplos
O exemplo seguinte imprime todos os descendentes de um 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
Este exemplo produz a seguinte saída:
Child
O exemplo seguinte é o mesmo, mas neste caso o XML está num namespace. Para mais informações, consulte Trabalhar com Namespaces 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
Este exemplo produz a seguinte saída:
{http://www.adventure-works.com}Child
Observações
Este método utiliza execução diferida.