XNode.ElementsBeforeSelf 方法

定义

按文档顺序返回此节点之前同级元素的集合。

重载

名称 说明
ElementsBeforeSelf()

按文档顺序返回此节点之前同级元素的集合。

ElementsBeforeSelf(XName)

按文档顺序返回此节点之前已筛选的同级元素集合。 集合中仅包含具有匹配 XName 的元素。

注解

此方法使用延迟执行。

ElementsBeforeSelf()

Source:
XNode.cs
Source:
XNode.cs
Source:
XNode.cs
Source:
XNode.cs
Source:
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)

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

注解

此方法仅包括返回的集合中的同级。 它不包括后代。

此方法使用延迟执行。

另请参阅

适用于