XNode.Ancestors Metoda
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Zwraca kolekcję elementów modułu ancestor tego węzła.
Ancestors() |
Zwraca kolekcję elementów modułu ancestor tego węzła. |
Ancestors(XName) |
Zwraca odfiltrowaną kolekcję elementów modułu ancestor tego węzła. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName . |
Opcjonalnie można określić nazwę węzła, aby filtrować elementy modułu ancestor o określonej nazwie.
Węzły w zwróconej kolekcji są w odwrotnej kolejności dokumentów.
Ta metoda używa odroczonego wykonania.
- Źródło:
- XNode.cs
- Źródło:
- XNode.cs
- Źródło:
- XNode.cs
Zwraca kolekcję elementów modułu ancestor tego węzła.
public:
System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ Ancestors();
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Ancestors();
member this.Ancestors : unit -> seq<System.Xml.Linq.XElement>
Public Function Ancestors () As IEnumerable(Of XElement)
Zwraca
XElement Część IEnumerable<T> elementów modułu ancestor tego węzła.
Przykłady
W poniższym przykładzie użyto tej metody do wyliczenia elementów podrzędnych węzła.
XElement xmlTree = new XElement("Root",
new XElement("Child",
new XElement("GrandChild", "content")
)
);
IEnumerable<XElement> grandChild = xmlTree.Descendants("GrandChild");
foreach (XElement el in grandChild.Ancestors())
Console.WriteLine(el.Name);
Dim xmlTree As XElement = _
<Root>
<Child>
<GrandChild>content</GrandChild>
</Child>
</Root>
Dim grandChild As IEnumerable(Of XElement) = xmlTree...<GrandChild>
For Each el In grandChild.Ancestors()
Console.WriteLine(el.Name)
Next
Ten przykład generuje następujące wyniki:
Child
Root
Uwagi
Ta metoda nie zwraca się w wynikach.
Węzły w zwróconej kolekcji są w odwrotnej kolejności dokumentów.
Ta metoda używa odroczonego wykonania.
Zobacz też
Dotyczy
.NET 10 i inne wersje
Produkt | Wersje |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- Źródło:
- XNode.cs
- Źródło:
- XNode.cs
- Źródło:
- XNode.cs
Zwraca odfiltrowaną kolekcję elementów modułu ancestor tego węzła. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName .
public:
System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ Ancestors(System::Xml::Linq::XName ^ name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Ancestors(System.Xml.Linq.XName name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Ancestors(System.Xml.Linq.XName? name);
member this.Ancestors : System.Xml.Linq.XName -> seq<System.Xml.Linq.XElement>
Public Function Ancestors (name As XName) As IEnumerable(Of XElement)
Parametry
Zwraca
XElement Część IEnumerable<T> elementów modułu ancestor tego węzła. W kolekcji znajdują się tylko elementy, które mają dopasowanie XName .
Węzły w zwróconej kolekcji są w odwrotnej kolejności dokumentów.
Ta metoda używa odroczonego wykonania.
Przykłady
W poniższym przykładzie użyto tej metody.
XElement xmlTree = new XElement("Root",
new XElement("Child",
new XElement("GrandChild", "content")
)
);
IEnumerable<XElement> grandChild = xmlTree.Descendants("GrandChild");
foreach (XElement el in grandChild.Ancestors("Child"))
Console.WriteLine(el.Name);
Dim xmlTree As XElement = _
<Root>
<Child>
<GrandChild>content</GrandChild>
</Child>
</Root>
Dim grandChild As IEnumerable(Of XElement) = xmlTree...<GrandChild>
For Each el In grandChild.Ancestors("Child")
Console.WriteLine(el.Name)
Next
Ten przykład generuje następujące wyniki:
Child
Uwagi
Ta metoda nie zwróci się w wynikach.
Zobacz też
Dotyczy
.NET 10 i inne wersje
Produkt | Wersje |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Opinia o produkcie .NET
.NET to projekt typu open source. Wybierz link, aby przekazać opinię: