XElement.AncestorsAndSelf メソッド

定義

この要素およびこの要素の先祖を格納している、要素のコレクションを返します。

オーバーロード

AncestorsAndSelf()

この要素およびこの要素の先祖を格納している、要素のコレクションを返します。

AncestorsAndSelf(XName)

この要素およびこの要素の先祖を格納している、フィルター処理された要素のコレクションを返します。 一致する XName を持つ要素のみがコレクションに含められます。

注釈

返されるコレクション内の要素は、逆のドキュメント順序です。

このメソッドは遅延実行を使用します。

AncestorsAndSelf()

この要素およびこの要素の先祖を格納している、要素のコレクションを返します。

public:
 System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ AncestorsAndSelf();
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> AncestorsAndSelf ();
member this.AncestorsAndSelf : unit -> seq<System.Xml.Linq.XElement>
Public Function AncestorsAndSelf () As IEnumerable(Of XElement)

戻り値

IEnumerable<XElement>

この要素およびこの要素の先祖を格納している、要素の XElementIEnumerable<T>

次の例では、XML ツリーを作成します。 その後、要素を GrandChild 検索し、その先祖を出力します。

XElement xmlTree = new XElement("Root",  
    new XElement("Child",  
        new XElement("GrandChild", "element content")  
    )  
);  
XElement gc = xmlTree.Element("Child").Element("GrandChild");  
IEnumerable<XElement> aas =  
    from el in gc.AncestorsAndSelf()  
    select el;  
foreach (XElement el in aas)  
    Console.WriteLine(el.Name);  
Dim xmlTree As XElement = _   
    <Root>  
        <Child>  
            <GrandChild>element content</GrandChild>  
        </Child>  
    </Root>  

Dim GC As XElement = xmlTree.<Child>.<GrandChild>(0)  

Dim aas As IEnumerable(Of XElement) = _  
    From el In GC.AncestorsAndSelf() _  
    Select el  

For Each el In aas  
    Console.WriteLine(el.Name)  
Next  

この例を実行すると、次の出力が生成されます。

GrandChild  
Child  
Root  

注釈

返されるコレクション内の要素は、逆のドキュメント順序です。

このメソッドは遅延実行を使用します。

こちらもご覧ください

適用対象

AncestorsAndSelf(XName)

この要素およびこの要素の先祖を格納している、フィルター処理された要素のコレクションを返します。 一致する XName を持つ要素のみがコレクションに含められます。

public:
 System::Collections::Generic::IEnumerable<System::Xml::Linq::XElement ^> ^ AncestorsAndSelf(System::Xml::Linq::XName ^ name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> AncestorsAndSelf (System.Xml.Linq.XName name);
public System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement> AncestorsAndSelf (System.Xml.Linq.XName? name);
member this.AncestorsAndSelf : System.Xml.Linq.XName -> seq<System.Xml.Linq.XElement>
Public Function AncestorsAndSelf (name As XName) As IEnumerable(Of XElement)

パラメーター

name
XName

照合する XName

戻り値

IEnumerable<XElement>

この要素およびこの要素の先祖を格納している、IEnumerable<T>XElement。 一致する XName を持つ要素のみがコレクションに含められます。

次の例では、これを使用します。

XElement xmlTree = new XElement("Root",  
    new XElement("Child",  
        new XElement("GrandChild", "element content")  
    )  
);  
XElement gc = xmlTree.Element("Child").Element("GrandChild");  
IEnumerable<XElement> aas = gc.AncestorsAndSelf("Child");  
foreach (XElement el in aas)  
    Console.WriteLine(el.Name);  
Dim xmlTree As XElement = _   
    <Root>  
        <Child>  
            <GrandChild>element content</GrandChild>  
        </Child>  
    </Root>  

Dim GC As XElement = xmlTree.<Child>.<GrandChild>(0)  
Dim aas As IEnumerable(Of XElement) = GC.AncestorsAndSelf("Child")  
For Each el In aas  
    Console.WriteLine(el.Name)  
Next  

この例を実行すると、次の出力が生成されます。

Child  

注釈

返されるコレクション内の要素は、逆のドキュメント順序です。

このメソッドは遅延実行を使用します。

こちらもご覧ください

適用対象