XElement.DescendantsAndSelf 方法

定義

依照文件順序,傳回包含這個元素的元素集合,以及這個元素的子系元素。Returns a collection of elements that contain this element, and all descendant elements of this element, in document order.

多載

DescendantsAndSelf(XName)

依照文件順序,傳回包含這個項目的已篩選項目集合,以及這個項目的所有子代項目。Returns a filtered collection of elements that contain this element, and all descendant elements of this element, in document order. 集合中只會包含具有相符之 XName 的項目。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.

備註

這個方法會使用延後的執行。This method uses deferred execution.

DescendantsAndSelf(XName)

依照文件順序,傳回包含這個項目的已篩選項目集合,以及這個項目的所有子代項目。Returns a filtered collection of elements that contain this element, and all descendant elements of this element, in document order. 集合中只會包含具有相符之 XName 的項目。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);
member this.DescendantsAndSelf : System.Xml.Linq.XName -> seq<System.Xml.Linq.XElement>
Public Function DescendantsAndSelf (name As XName) As IEnumerable(Of XElement)

參數

name
XName

要比對的 XNameThe XName to match.

傳回

IEnumerable<T>XElement,依照文件順序包含這個項目及這個項目的所有子代項目。An IEnumerable<T> of XElement that contain this element, and all descendant elements of this element, in document order. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

範例

下列範例會建立 XML 樹狀結構,然後使用這個。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  

備註

這個方法會使用延後的執行。This method uses deferred execution.

另請參閱

DescendantsAndSelf()

依照文件順序,傳回包含這個項目的項目集合,以及這個項目的子代項目。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)

傳回

項目之 IEnumerable<T>XElement,依照文件順序包含這個項目及這個項目的所有子代項目。An IEnumerable<T> of XElement of elements that contain this element, and all descendant elements of this element, in document order.

範例

下列範例會建立 XML 樹狀結構,然後使用這個。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  

備註

這個方法會使用延後的執行。This method uses deferred execution.

另請參閱

適用於