XNode.ElementsBeforeSelf 方法

定義

回傳節點前的兄弟元素集合,依文件順序排列。

多載

名稱 Description
ElementsBeforeSelf()

回傳節點前的兄弟元素集合,依文件順序排列。

ElementsBeforeSelf(XName)

回傳此節點前的兄弟元素篩選後集合,依文件順序排列。 集合中只會包含具有相符 XName 的專案。

備註

此方法使用延遲執行。

ElementsBeforeSelf()

來源:
XNode.cs
來源:
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
來源:
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

備註

此方法僅包含回傳集合中的兄弟姊妹。 不包括後代。

此方法使用延遲執行。

另請參閱

適用於