XNode.ElementsAfterSelf 方法

定义

按文档顺序返回此节点后的同级元素集合。Returns a collection of the sibling elements after this node, in document order.

重载

ElementsAfterSelf()

按文档顺序返回此节点后的同级元素集合。Returns a collection of the sibling elements after this node, in document order.

ElementsAfterSelf(XName)

按文档顺序返回此节点后经过筛选的同级元素的集合。Returns a filtered collection of the sibling elements after this node, in document order. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

注解

此方法使用延迟执行。This method uses deferred execution.

ElementsAfterSelf()

按文档顺序返回此节点后的同级元素集合。Returns a collection of the sibling elements after this node, in document order.

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

返回

此节点后同级元素(按文档顺序排列)的 XElementIEnumerable<T>An IEnumerable<T> of XElement of the sibling elements after this node, in document order.

示例

下面的示例创建一个具有一些复杂内容的元素。The following example creates an element with some complex content. 然后,它使用此方法以文档顺序检索节点。It then uses this method to retrieve the nodes in document order.

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.ElementsAfterSelf();  
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.ElementsAfterSelf()  
For Each el In elements  
    Console.WriteLine(el.Name)  
Next  

该示例产生下面的输出:This example produces the following output:

Child4  
Child5  

注解

此方法仅在返回的集合中包含同级。This method only includes siblings in the returned collection. 它不包括后代。It does not include descendants.

此方法使用延迟执行。This method uses deferred execution.

另请参阅

ElementsAfterSelf(XName)

按文档顺序返回此节点后经过筛选的同级元素的集合。Returns a filtered collection of the sibling elements after this node, in document order. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

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

参数

name
XName

要匹配的 XNameThe XName to match.

返回

此节点后同级元素(按文档顺序排列)的 XElementIEnumerable<T>An IEnumerable<T> of XElement of the sibling elements after this node, in document order. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

示例

下面的示例创建一个具有一些复杂内容的元素。The following example creates an element with some complex content. 然后,它使用此方法按文档顺序检索同级元素。It then uses this method to retrieve the sibling elements, in document order.

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.ElementsAfterSelf("Child4");  
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.ElementsAfterSelf("Child4")  
  
For Each el In elements  
    Console.WriteLine(el.Name)  
Next  

该示例产生下面的输出:This example produces the following output:

Child4  

注解

此方法仅在返回的集合中包含同级。This method only includes siblings in the returned collection. 它不包括后代。It does not include descendants.

此方法使用延迟执行。This method uses deferred execution.

另请参阅

适用于