XElement.AncestorsAndSelf Método
Definição
Retorna uma coleção de elementos que contêm esse elemento e os ancestrais desse elemento.Returns a collection of elements that contain this element, and the ancestors of this element.
Sobrecargas
| AncestorsAndSelf() |
Retorna uma coleção de elementos que contêm esse elemento e os ancestrais desse elemento.Returns a collection of elements that contain this element, and the ancestors of this element. |
| AncestorsAndSelf(XName) |
Retorna uma coleção filtrada de elementos que contêm esse elemento e os ancestrais dele.Returns a filtered collection of elements that contain this element, and the ancestors of this element. Somente os elementos que têm um XName correspondente são incluídos na coleção.Only elements that have a matching XName are included in the collection. |
Comentários
Os elementos na coleção retornada estão na ordem inversa do documento.The elements in the returned collection are in reverse document order.
Este método utiliza execução adiada.This method uses deferred execution.
AncestorsAndSelf()
Retorna uma coleção de elementos que contêm esse elemento e os ancestrais desse elemento.Returns a collection of elements that contain this element, and the ancestors of this element.
public:
System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ AncestorsAndSelf();
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> AncestorsAndSelf ();
member this.AncestorsAndSelf : unit -> seq<System.Xml.Linq.XElement>
Public Function AncestorsAndSelf () As IEnumerable(Of XElement)
Retornos
Um IEnumerable<T> de XElement de elementos que contêm esse elemento e os ancestrais dele.An IEnumerable<T> of XElement of elements that contain this element, and the ancestors of this element.
Exemplos
O exemplo a seguir cria uma árvore XML.The following example creates an XML tree. Em seguida, ele localiza o GrandChild elemento e, em seguida, imprime os ancestrais dele.It then finds the GrandChild element, and then prints the ancestors of it.
XElement xmlTree = new XElement("Root",
new XElement("Child",
new XElement("GrandChild", "element content")
)
);
XElement gc = xmlTree.Element("Child").Element("GrandChild");
IEnumerable<XElement> aas =
from el in gc.AncestorsAndSelf()
select el;
foreach (XElement el in aas)
Console.WriteLine(el.Name);
Dim xmlTree As XElement = _
<Root>
<Child>
<GrandChild>element content</GrandChild>
</Child>
</Root>
Dim GC As XElement = xmlTree.<Child>.<GrandChild>(0)
Dim aas As IEnumerable(Of XElement) = _
From el In GC.AncestorsAndSelf() _
Select el
For Each el In aas
Console.WriteLine(el.Name)
Next
Esse exemplo gera a saída a seguir:This example produces the following output:
GrandChild
Child
Root
Comentários
Os elementos na coleção retornada estão na ordem inversa do documento.The elements in the returned collection are in reverse document order.
Este método utiliza execução adiada.This method uses deferred execution.
Confira também
Aplica-se a
AncestorsAndSelf(XName)
Retorna uma coleção filtrada de elementos que contêm esse elemento e os ancestrais dele.Returns a filtered collection of elements that contain this element, and the ancestors of this element. Somente os elementos que têm um XName correspondente são incluídos na coleção.Only elements that have a matching XName are included in the collection.
public:
System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ AncestorsAndSelf(System::Xml::Linq::XName ^ name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> AncestorsAndSelf (System.Xml.Linq.XName name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> AncestorsAndSelf (System.Xml.Linq.XName? name);
member this.AncestorsAndSelf : System.Xml.Linq.XName -> seq<System.Xml.Linq.XElement>
Public Function AncestorsAndSelf (name As XName) As IEnumerable(Of XElement)
Parâmetros
Retornos
Um IEnumerable<T> de XElement que contêm esse elemento e os ancestrais dele.An IEnumerable<T> of XElement that contain this element, and the ancestors of this element. Somente os elementos que têm um XName correspondente são incluídos na coleção.Only elements that have a matching XName are included in the collection.
Exemplos
O exemplo a seguir usa isso.The following example uses this .
XElement xmlTree = new XElement("Root",
new XElement("Child",
new XElement("GrandChild", "element content")
)
);
XElement gc = xmlTree.Element("Child").Element("GrandChild");
IEnumerable<XElement> aas = gc.AncestorsAndSelf("Child");
foreach (XElement el in aas)
Console.WriteLine(el.Name);
Dim xmlTree As XElement = _
<Root>
<Child>
<GrandChild>element content</GrandChild>
</Child>
</Root>
Dim GC As XElement = xmlTree.<Child>.<GrandChild>(0)
Dim aas As IEnumerable(Of XElement) = GC.AncestorsAndSelf("Child")
For Each el In aas
Console.WriteLine(el.Name)
Next
Esse exemplo gera a saída a seguir:This example produces the following output:
Child
Comentários
Os elementos na coleção retornada estão na ordem inversa do documento.The elements in the returned collection are in reverse document order.
Este método utiliza execução adiada.This method uses deferred execution.