XContainer.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 následnických prvků pro tento dokument nebo prvek v pořadí dokumentu.
Přetížení
| Name | Description |
|---|---|
| Descendants() |
Vrátí kolekci následnických prvků pro tento dokument nebo prvek v pořadí dokumentu. |
| Descendants(XName) |
Vrátí filtrovanou kolekci následnických prvků pro tento dokument nebo prvek v pořadí dokumentu. Do kolekce jsou zahrnuty pouze prvky, které mají odpovídající XName. |
Poznámky
Tato metoda používá odložené spuštění.
Descendants()
- Zdroj:
- XContainer.cs
- Zdroj:
- XContainer.cs
- Zdroj:
- XContainer.cs
- Zdroj:
- XContainer.cs
- Zdroj:
- XContainer.cs
Vrátí kolekci následnických prvků pro tento dokument nebo prvek v pořadí dokumentu.
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)
Návraty
A IEnumerable<T> obsahující XElement potomky prvků XContainer.
Příklady
Následující příklad vytvoří strom XML a pak pomocí této metody osy načte potomky.
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
Tento příklad vytvoří následující výstup:
Child
GrandChild
Poznámky
Všimněte si, že tato metoda nebude vracet sám sebe ve výsledném IEnumerable<T>. Podívejte DescendantsAndSelf se, jestli potřebujete do výsledků zahrnout aktuální.XElement
Tato metoda používá odložené spuštění.
Viz také
Platí pro
Descendants(XName)
- Zdroj:
- XContainer.cs
- Zdroj:
- XContainer.cs
- Zdroj:
- XContainer.cs
- Zdroj:
- XContainer.cs
- Zdroj:
- XContainer.cs
Vrátí filtrovanou kolekci následnických prvků pro tento dokument nebo prvek v pořadí dokumentu. Do kolekce jsou zahrnuty pouze prvky, které mají odpovídající XName.
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)
Parametry
Návraty
Hodnota IEnumerable<T> obsahující potomky prvkůXElement, které odpovídají zadanému XContainer.XName
Příklady
Následující příklad vytiskne všechny potomky elementu.
// 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
Tento příklad vytvoří následující výstup:
Child
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.
// 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
Tento příklad vytvoří následující výstup:
{http://www.adventure-works.com}Child
Poznámky
Tato metoda používá odložené spuštění.