XElement.DescendantsAndSelf 方法

定義

依照文件順序,傳回包含這個元素的元素集合,以及這個元素的子系元素。

多載

DescendantsAndSelf(XName)

依照文件順序,傳回包含這個元素的已篩選元素集合,以及這個元素的所有子系元素。 集合中只會包含具有相符之 XName 的項目。

DescendantsAndSelf()

依照文件順序,傳回包含這個元素的元素集合,以及這個元素的子系元素。

備註

這個方法會使用延後的執行。

DescendantsAndSelf(XName)

依照文件順序,傳回包含這個元素的已篩選元素集合,以及這個元素的所有子系元素。 集合中只會包含具有相符之 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)

參數

name
XName

要比對的 XName

傳回

IEnumerable<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()

依照文件順序,傳回包含這個元素的元素集合,以及這個元素的子系元素。

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<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  

備註

這個方法會使用延後的執行。

另請參閱

適用於