XElement.DescendantsAndSelf 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳包含此元素及其所有後代元素的元素集合,依文件順序排列。
多載
| 名稱 | Description |
|---|---|
| DescendantsAndSelf(XName) |
回傳包含此元素及其所有後代元素的篩選後元素集合,依文件順序排列。 集合中只會包含具有相符 XName 的專案。 |
| DescendantsAndSelf() |
回傳包含此元素及其所有後代元素的元素集合,依文件順序排列。 |
備註
此方法使用延遲執行。
DescendantsAndSelf(XName)
- 來源:
- XElement.cs
- 來源:
- XElement.cs
- 來源:
- XElement.cs
- 來源:
- XElement.cs
- 來源:
- XElement.cs
回傳包含此元素及其所有後代元素的篩選後元素集合,依文件順序排列。 集合中只會包含具有相符 XName 的專案。
public:
System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ DescendantsAndSelf(System::Xml::Linq::XName ^ name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> DescendantsAndSelf(System.Xml.Linq.XName name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> DescendantsAndSelf(System.Xml.Linq.XName? name);
member this.DescendantsAndSelf : System.Xml.Linq.XName -> seq<System.Xml.Linq.XElement>
Public Function DescendantsAndSelf (name As XName) As IEnumerable(Of XElement)
參數
傳回
IEnumerable<T>一個 包含XElement此元素及其所有後代元素,依文件順序排列。 集合中只會包含具有相符 XName 的專案。
範例
以下範例建立一個 XML 樹,並使用此 。
XElement xmlTree = new XElement("Root",
new XAttribute("Att1", "AttributeContent"),
new XElement("Child",
new XText("Some text"),
new XElement("GrandChild", "element content")
)
);
IEnumerable<XElement> das = xmlTree.DescendantsAndSelf("Child");
foreach (XElement el in das)
Console.WriteLine(el.Name);
Dim xmlTree As XElement = _
<Root Att1="AttributeContent">
<Child>Some text
<GrandChild>element content</GrandChild>
</Child>
</Root>
Dim das As IEnumerable(Of XElement) = xmlTree.DescendantsAndSelf("Child")
For Each el In das
Console.WriteLine(el.Name)
Next
此範例會產生下列輸出:
Child
備註
此方法使用延遲執行。
另請參閱
適用於
DescendantsAndSelf()
- 來源:
- XElement.cs
- 來源:
- XElement.cs
- 來源:
- XElement.cs
- 來源:
- XElement.cs
- 來源:
- XElement.cs
回傳包含此元素及其所有後代元素的元素集合,依文件順序排列。
public:
System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ DescendantsAndSelf();
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> DescendantsAndSelf();
member this.DescendantsAndSelf : unit -> seq<System.Xml.Linq.XElement>
Public Function DescendantsAndSelf () As IEnumerable(Of XElement)
傳回
IEnumerable<T>一組XElement包含此元素及其所有後代元素的元素,依文件順序排列。
範例
以下範例建立一個 XML 樹,並使用此 。
XElement xmlTree = new XElement("Root",
new XAttribute("Att1", "AttributeContent"),
new XElement("Child",
new XText("Some text"),
new XElement("GrandChild", "element content")
)
);
IEnumerable<XElement> das =
from el in xmlTree.DescendantsAndSelf()
select el;
foreach (XElement el in das)
Console.WriteLine(el.Name);
Dim xmlTree As XElement = _
<Root Att1="AttributeContent">
<Child>Some text
<GrandChild>element content</GrandChild>
</Child>
</Root>
Dim das As IEnumerable(Of XElement) = _
From el In xmlTree.DescendantsAndSelf() _
Select el
For Each el In das
Console.WriteLine(el.Name)
Next
此範例會產生下列輸出:
Root
Child
GrandChild
備註
此方法使用延遲執行。