次の方法で共有


XNode.ElementsBeforeSelf メソッド

定義

このノードの前にある兄弟要素のコレクションをドキュメント順に返します。

オーバーロード

ElementsBeforeSelf()

このノードの前にある兄弟要素のコレクションをドキュメント順に返します。

ElementsBeforeSelf(XName)

このノードの前にある兄弟要素のフィルター処理されたコレクションをドキュメント順に返します。 一致する XName を持つ要素のみがコレクションに含められます。

注釈

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

ElementsBeforeSelf()

ソース:
XNode.cs
ソース:
XNode.cs
ソース:
XNode.cs
ソース:
XNode.cs

このノードの前にある兄弟要素のコレクションをドキュメント順に返します。

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

戻り値

このノードの前にある兄弟要素の IEnumerable<T>XElement (ドキュメント順)。

次の例では、この軸メソッドを使用します。

XElement xmlTree = new XElement("Root",
    new XText("Text content."),
    new XElement("Child1", "child1 content"),
    new XElement("Child2", "child2 content"),
    new XElement("Child3", "child3 content"),
    new XText("More text content."),
    new XElement("Child4", "child4 content"),
    new XElement("Child5", "child5 content")
);
XElement child = xmlTree.Element("Child3");
IEnumerable<XElement> elements = child.ElementsBeforeSelf();
foreach (XElement el in elements)
    Console.WriteLine(el.Name);
Dim xmlTree As XElement = _
        <Root>Text content.
            <Child1>child1 content</Child1>
            <Child2>child2 content</Child2>
            <Child3>child3 content</Child3>More text content.
            <Child4>child4 content</Child4>
            <Child5>child5 content</Child5>
        </Root>

Dim child As XElement = xmlTree.<Child3>(0)
Dim elements As IEnumerable(Of XElement) = child.ElementsBeforeSelf()

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

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

Child1
Child2

注釈

このメソッドには、返されるコレクション内の兄弟のみが含まれます。 子孫は含まれません。

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

こちらもご覧ください

適用対象

ElementsBeforeSelf(XName)

ソース:
XNode.cs
ソース:
XNode.cs
ソース:
XNode.cs
ソース:
XNode.cs

このノードの前にある兄弟要素のフィルター処理されたコレクションをドキュメント順に返します。 一致する XName を持つ要素のみがコレクションに含められます。

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

パラメーター

name
XName

照合する XName

戻り値

このノードの前にある兄弟要素の IEnumerable<T>XElement (ドキュメント順)。 一致する XName を持つ要素のみがコレクションに含められます。

次の例では、このメソッドを使用します。

XElement xmlTree = new XElement("Root",
    new XText("Text content."),
    new XElement("Child1", "child1 content"),
    new XElement("Child2", "child2 content"),
    new XElement("Child3", "child3 content"),
    new XText("More text content."),
    new XElement("Child4", "child4 content"),
    new XElement("Child5", "child5 content")
);
XElement child = xmlTree.Element("Child3");
IEnumerable<XElement> elements = child.ElementsBeforeSelf("Child2");
foreach (XElement el in elements)
    Console.WriteLine(el.Name);
Dim xmlTree As XElement = _
        <Root>Text content.
            <Child1>child1 content</Child1>
            <Child2>child2 content</Child2>
            <Child3>child3 content</Child3>More text content.
            <Child4>child4 content</Child4>
            <Child5>child5 content</Child5>
        </Root>

Dim child As XElement = xmlTree.<Child3>(0)
Dim elements As IEnumerable(Of XElement) = child.ElementsBeforeSelf("Child2")

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

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

Child2

注釈

このメソッドには、返されるコレクション内の兄弟のみが含まれます。 子孫は含まれません。

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

こちらもご覧ください

適用対象