XElement.DescendantsAndSelf Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a collection of elements that contain this element, and all descendant elements of this element, in document order.
Overloads
DescendantsAndSelf(XName) |
Returns a filtered collection of elements that contain this element, and all descendant elements of this element, in document order. Only elements that have a matching XName are included in the collection. |
DescendantsAndSelf() |
Returns a collection of elements that contain this element, and all descendant elements of this element, in document order. |
Remarks
This method uses deferred execution.
DescendantsAndSelf(XName)
- Source:
- XElement.cs
- Source:
- XElement.cs
- Source:
- XElement.cs
Returns a filtered collection of elements that contain this element, and all descendant elements of this element, in document order. Only elements that have a matching XName are included in the collection.
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)
Parameters
Returns
An IEnumerable<T> of XElement that contain this element, and all descendant elements of this element, in document order. Only elements that have a matching XName are included in the collection.
Examples
The following example creates an XML tree, and then uses this .
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
This example produces the following output:
Child
Remarks
This method uses deferred execution.
See also
Applies to
DescendantsAndSelf()
- Source:
- XElement.cs
- Source:
- XElement.cs
- Source:
- XElement.cs
Returns a collection of elements that contain this element, and all descendant elements of this element, in document order.
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)
Returns
An IEnumerable<T> of XElement of elements that contain this element, and all descendant elements of this element, in document order.
Examples
The following example creates an XML tree, and then uses this .
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
This example produces the following output:
Root
Child
GrandChild
Remarks
This method uses deferred execution.
See also
Applies to
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈