Extensions.Descendants Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Vrátí kolekci prvků, které obsahují potomky prvků každého prvku a dokumentu ve zdrojové kolekci.
Přetížení
| Name | Description |
|---|---|
| Descendants<T>(IEnumerable<T>, XName) |
Vrátí filtrovanou kolekci prvků, která obsahuje potomky prvků každého prvku a dokumentu ve zdrojové kolekci. Do kolekce jsou zahrnuty pouze prvky, které mají odpovídající XName. |
| Descendants<T>(IEnumerable<T>) |
Vrátí kolekci prvků, které obsahují potomky prvků každého prvku a dokumentu ve zdrojové kolekci. |
Poznámky
Visual Basic uživatelé mohou k načtení následnických prvků kolekce použít integrovanou osu potomků XML. Integrovaná osa ale načte pouze potomky se zadaným názvem. Pokud Visual Basic uživatelé chtějí načíst všechny potomky, musí tuto metodu osy použít explicitně.
Tato metoda používá odložené spuštění.
Descendants<T>(IEnumerable<T>, XName)
- Zdroj:
- Extensions.cs
- Zdroj:
- Extensions.cs
- Zdroj:
- Extensions.cs
- Zdroj:
- Extensions.cs
- Zdroj:
- Extensions.cs
Vrátí filtrovanou kolekci prvků, která obsahuje potomky prvků každého prvku a dokumentu ve zdrojové kolekci. Do kolekce jsou zahrnuty pouze prvky, které mají odpovídající XName.
public:
generic <typename T>
where T : System::Xml::Linq::XContainer[System::Runtime::CompilerServices::Extension]
static System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ Descendants(System::Collections::Generic::IEnumerable<T> ^ source, System::Xml::Linq::XName ^ name);
public static System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Descendants<T>(this System.Collections.Generic.IEnumerable<T> source, System.Xml.Linq.XName name) where T : System.Xml.Linq.XContainer;
public static System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Descendants<T>(this System.Collections.Generic.IEnumerable<T?> source, System.Xml.Linq.XName? name) where T : System.Xml.Linq.XContainer;
static member Descendants : seq<'T (requires 'T :> System.Xml.Linq.XContainer)> * System.Xml.Linq.XName -> seq<System.Xml.Linq.XElement> (requires 'T :> System.Xml.Linq.XContainer)
<Extension()>
Public Function Descendants(Of T As XContainer) (source As IEnumerable(Of T), name As XName) As IEnumerable(Of XElement)
Parametry typu
- T
Typ objektů, které jsou sourceomezeny na XContainer.
Parametry
- source
- IEnumerable<T>
Hodnota IEnumerable<T>XContainer obsahující zdrojovou kolekci.
Návraty
Z IEnumerable<T>XElement toho, která obsahuje potomky prvků každého prvku a dokumentu ve zdrojové kolekci. Do kolekce jsou zahrnuty pouze prvky, které mají odpovídající XName.
Příklady
Následující příklad načte kolekci dvou prvků a pak načte kolekci všech potomků dvou prvků, které mají zadaný název elementu.
XElement xmlTree = XElement.Parse(
@"<Root>
<Para>
<t>This is some text </t>
<b>
<t>where</t>
</b>
<t> all of the text nodes must be concatenated. </t>
</Para>
<Para>
<t>This is a second sentence.</t>
</Para>
</Root>");
string str =
(from el in xmlTree.Elements("Para").Descendants("t")
select (string)el)
.Aggregate(new StringBuilder(),
(sb, i) => sb.Append(i),
sb => sb.ToString());
Console.WriteLine(str);
Dim xmlTree As XElement = _
<Root>
<Para>
<t>This is some text </t>
<b>
<t>where</t>
</b>
<t> all of the text nodes must be concatenated. </t>
</Para>
<Para>
<t>This is a second sentence.</t>
</Para>
</Root>
Dim str As String = _
( _
From el In xmlTree.<Para>...<t> _
Select CStr(el) _
) _
.Aggregate(New StringBuilder(), _
Function(ByVal sb, ByVal i) sb.Append(i), _
Function(ByVal sb) sb.ToString())
Console.WriteLine(str)
Tento příklad vytvoří následující výstup:
This is some text where all of the text nodes must be concatenated. This is a second sentence.
Následující příklad je stejný, ale v tomto případě je XML v oboru názvů. Další informace naleznete v tématu Práce s obory názvů XML.
XNamespace aw = "http://www.adventure-works.com";
XElement xmlTree = XElement.Parse(
@"<Root xmlns='http://www.adventure-works.com'>
<Para>
<t>This is some text </t>
<b>
<t>where</t>
</b>
<t> all of the text nodes must be concatenated. </t>
</Para>
<Para>
<t>This is a second sentence.</t>
</Para>
</Root>");
string str =
(from el in xmlTree.Elements(aw + "Para").Descendants(aw + "t")
select (string)el)
.Aggregate(new StringBuilder(),
(sb, i) => sb.Append(i),
sb => sb.ToString());
Console.WriteLine(str);
Imports <xmlns="http://www.adventure-works.com">
Module Module1
Sub Main()
Dim xmlTree As XElement = _
<Root>
<Para>
<t>This is some text </t>
<b>
<t>where</t>
</b>
<t> all of the text nodes must be concatenated. </t>
</Para>
<Para>
<t>This is a second sentence.</t>
</Para>
</Root>
Dim str As String = _
( _
From el In xmlTree.<Para>...<t> _
Select CStr(el) _
) _
.Aggregate(New StringBuilder(), _
Function(sb, i) sb.Append(i), _
Function(sb) sb.ToString())
Console.WriteLine(str)
End Sub
End Module
Tento příklad vytvoří následující výstup:
This is some text where all of the text nodes must be concatenated. This is a second sentence.
Poznámky
Visual Basic uživatelé můžou použít osy Language-Integrated v Visual Basic (LINQ to XML) namísto explicitního použití této metody osy.
Tato metoda používá odložené spuštění.
Viz také
- DescendantNodesAndSelf()
- DescendantNodes()
- Descendants()
- DescendantNodes<T>(IEnumerable<T>)
- Nodes<T>(IEnumerable<T>)
- System.Xml.Linq.XElement.DescendantsAndSelf
- System.Xml.Linq.Extensions.DescendantsAndSelf
- Přehled LINQ to XML
Platí pro
Descendants<T>(IEnumerable<T>)
- Zdroj:
- Extensions.cs
- Zdroj:
- Extensions.cs
- Zdroj:
- Extensions.cs
- Zdroj:
- Extensions.cs
- Zdroj:
- Extensions.cs
Vrátí kolekci prvků, které obsahují potomky prvků každého prvku a dokumentu ve zdrojové kolekci.
public:
generic <typename T>
where T : System::Xml::Linq::XContainer[System::Runtime::CompilerServices::Extension]
static System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ Descendants(System::Collections::Generic::IEnumerable<T> ^ source);
public static System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Descendants<T>(this System.Collections.Generic.IEnumerable<T> source) where T : System.Xml.Linq.XContainer;
public static System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> Descendants<T>(this System.Collections.Generic.IEnumerable<T?> source) where T : System.Xml.Linq.XContainer;
static member Descendants : seq<'T (requires 'T :> System.Xml.Linq.XContainer)> -> seq<System.Xml.Linq.XElement> (requires 'T :> System.Xml.Linq.XContainer)
<Extension()>
Public Function Descendants(Of T As XContainer) (source As IEnumerable(Of T)) As IEnumerable(Of XElement)
Parametry typu
- T
Typ objektů, které jsou sourceomezeny na XContainer.
Parametry
- source
- IEnumerable<T>
Hodnota IEnumerable<T>XContainer obsahující zdrojovou kolekci.
Návraty
Z IEnumerable<T>XElement toho, která obsahuje potomky prvků každého prvku a dokumentu ve zdrojové kolekci.
Příklady
Následující příklad načte kolekci prvků a pak pomocí této metody osy načte všechny sestupné prvky každé položky v kolekci prvků.
XElement xmlTree = XElement.Parse(
@"<Root>
<Para>
<t>This is some text </t>
<b>
<t>where</t>
</b>
<t> all of the nodes must be concatenated. </t>
</Para>
<Para>
<t>This is a second sentence.</t>
</Para>
</Root>");
IEnumerable<XElement> elList =
from el in xmlTree.Elements("Para").Descendants()
select el;
foreach (XElement el in elList)
Console.WriteLine(el);
Dim xmlTree As XElement = _
<Root>
<Para>
<t>This is some text </t>
<b>
<t>where</t>
</b>
<t> all of the nodes must be concatenated. </t>
</Para>
<Para>
<t>This is a second sentence.</t>
</Para>
</Root>
Dim elList = From el In xmlTree.<Para>.Descendants _
Select el
For Each el As XElement In elList
Console.WriteLine(el)
Next
Tento příklad vytvoří následující výstup:
<t>This is some text </t>
<b>
<t>where</t>
</b>
<t>where</t>
<t> all of the nodes must be concatenated. </t>
<t>This is a second sentence.</t>
Následující příklad je stejný, ale v tomto případě je XML v oboru názvů. Další informace naleznete v tématu Práce s obory názvů XML.
XNamespace aw = "http://www.adventure-works.com";
XElement xmlTree = XElement.Parse(
@"<Root xmlns='http://www.adventure-works.com'>
<Para>
<t>This is some text </t>
<b>
<t>where</t>
</b>
<t> all of the nodes must be concatenated. </t>
</Para>
<Para>
<t>This is a second sentence.</t>
</Para>
</Root>");
IEnumerable<XElement> elList =
from el in xmlTree.Elements(aw + "Para").Descendants()
select el;
foreach (XElement el in elList)
Console.WriteLine(el);
Imports <xmlns="http://www.adventure-works.com">
Module Module1
Sub Main()
Dim xmlTree As XElement = _
<Root>
<Para>
<t>This is some text </t>
<b>
<t>where</t>
</b>
<t> all of the nodes must be concatenated. </t>
</Para>
<Para>
<t>This is a second sentence.</t>
</Para>
</Root>
Dim elList = From el In xmlTree.<Para>.Descendants _
Select el
For Each el As XElement In elList
Console.WriteLine(el)
Next
End Sub
End Module
Tento příklad vytvoří následující výstup:
<t xmlns="http://www.adventure-works.com">This is some text </t>
<b xmlns="http://www.adventure-works.com">
<t>where</t>
</b>
<t xmlns="http://www.adventure-works.com">where</t>
<t xmlns="http://www.adventure-works.com"> all of the nodes must be concatenated. </t>
<t xmlns="http://www.adventure-works.com">This is a second sentence.</t>
Poznámky
Visual Basic uživatelé mohou k načtení následnických prvků kolekce použít integrovanou osu potomků XML. Integrovaná osa ale načte pouze potomky se zadaným názvem. Pokud Visual Basic uživatelé chtějí načíst všechny potomky, musí tuto metodu osy použít explicitně.
Tato metoda používá odložené spuštění.
Viz také
- DescendantNodesAndSelf()
- DescendantNodes()
- Descendants()
- DescendantNodes<T>(IEnumerable<T>)
- Nodes<T>(IEnumerable<T>)
- System.Xml.Linq.XElement.DescendantsAndSelf
- System.Xml.Linq.Extensions.DescendantsAndSelf
- Přehled LINQ to XML