Extensions.InDocumentOrder(IEnumerable<T>) Extensions.InDocumentOrder(IEnumerable<T>) Extensions.InDocumentOrder(IEnumerable<T>) Extensions.InDocumentOrder(IEnumerable<T>) Method

定義

傳回包含來源集合中所有節點的節點集合,依據文件順序來排序。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> IEnumerable<T> IEnumerable<T>

IEnumerable<T>XNode,其中包含來源集合。An IEnumerable<T> of XNode that contains the source collection.

傳回

包含來源集合中所有節點 (依據文件順序排序) 之 IEnumerable<T>XNodeAn 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.

適用於

另請參閱