XElement.AncestorsAndSelf メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
この要素を含む要素のコレクションと、この要素の先祖を返します。
オーバーロード
| 名前 | 説明 |
|---|---|
| AncestorsAndSelf() |
この要素を含む要素のコレクションと、この要素の先祖を返します。 |
| AncestorsAndSelf(XName) |
この要素を含む要素のフィルター処理されたコレクションと、この要素の先祖を返します。 コレクションには、一致する XName を持つ要素のみが含まれます。 |
注釈
返されるコレクション内の要素は、逆のドキュメントの順序になります。
このメソッドでは、遅延実行が使用されます。
AncestorsAndSelf()
- ソース:
- XElement.cs
- ソース:
- XElement.cs
- ソース:
- XElement.cs
- ソース:
- XElement.cs
- ソース:
- XElement.cs
この要素を含む要素のコレクションと、この要素の先祖を返します。
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<T>と、この要素の先祖のXElement。
例
次の例では、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)
- ソース:
- XElement.cs
- ソース:
- XElement.cs
- ソース:
- XElement.cs
- ソース:
- XElement.cs
- ソース:
- XElement.cs
この要素を含む要素のフィルター処理されたコレクションと、この要素の先祖を返します。 コレクションには、一致する 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)
パラメーター
返品
この要素を含む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
注釈
返されるコレクション内の要素は、逆のドキュメントの順序になります。
このメソッドでは、遅延実行が使用されます。