Extensions.InDocumentOrder<T>(IEnumerable<T>) 方法

定义

返回节点集合(其中包含源集合中的所有节点),并按文档顺序排列。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

public:
generic <typename T>
 where T : System::Xml::Linq::XNode[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<T> ^ InDocumentOrder(System::Collections::Generic::IEnumerable<T> ^ source);
public static System.Collections.Generic.IEnumerable<T> InDocumentOrder<T> (this System.Collections.Generic.IEnumerable<T> source) where T : System.Xml.Linq.XNode;
static member InDocumentOrder : seq<'T (requires 'T :> System.Xml.Linq.XNode)> -> seq<'T (requires 'T :> System.Xml.Linq.XNode)> (requires 'T :> System.Xml.Linq.XNode)
<Extension()>
Public Function InDocumentOrder(Of T As XNode) (source As IEnumerable(Of T)) As IEnumerable(Of T)

类型参数

T

source 中对象的类型,被约束为 XNodeThe type of the objects in source, constrained to XNode.

参数

source
IEnumerable<T>

一个包含源集合的 IEnumerable<T>XNodeAn IEnumerable<T> of XNode that contains the source collection.

返回

IEnumerable<T>XNode,其中包含源集合中的所有节点(按文档顺序排列)。An IEnumerable<T> of XNode that contains all nodes in the source collection, sorted in document order.

示例

下面的示例创建一个不按文档顺序排列的节点集合,然后使用此轴创建一个新集合,其中的节点按文档顺序排列。The following example creates a collection of nodes that are not in document order, and then uses this axis to create a new collection where the nodes are in document order.

XElement xmlTree = new XElement("Root",  
    new XElement("Item",  
        new XElement("aaa", 1),  
        new XElement("bbb", 2)  
    ),  
    new XElement("Item",  
        new XElement("ccc", 3),  
        new XElement("aaa", 4)  
    ),  
    new XElement("Item",  
        new XElement("ddd", 5),  
        new XElement("eee", 6)  
    )  
);  
  
XElement[] elementList = {  
    xmlTree.Descendants("ddd").First(),  
    xmlTree.Descendants("ccc").First(),  
    xmlTree.Descendants("aaa").First()  
};  
  
IEnumerable<XElement> inDocOrder = elementList.InDocumentOrder();  
  
foreach (XElement el in inDocOrder)  
    Console.WriteLine(el);  
Dim xmlTree As XElement = _  
    <Root>  
        <Item>  
            <aaa>1</aaa>  
            <bbb>2</bbb>  
        </Item>  
  
        <Item>  
            <ccc>3</ccc>  
            <aaa>4</aaa>  
        </Item>  
  
        <Item>  
            <ddd>5</ddd>  
            <eee>6</eee>  
        </Item>  
    </Root>  
  
Dim elementList() As XElement = _  
    { _  
        xmlTree...<ddd>(0), _  
        xmlTree...<ccc>(0), _  
        xmlTree...<aaa>(0) _  
    }  
  
Dim inDocOrder = elementList.InDocumentOrder  
  
For Each el As XElement In inDocOrder  
    Console.WriteLine(el)  
Next  
  

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

<aaa>1</aaa>  
<ccc>3</ccc>  
<ddd>5</ddd>  

注解

此轴方法使用延迟执行。This axis method uses deferred execution. 但是,它首先枚举其源集合,按文档顺序对节点进行排序,然后生成结果。However, it first enumerates its source collection, the sorts the nodes in document order, and then yields the results.

适用于

另请参阅