Extensions.InDocumentOrder<T>(IEnumerable<T>) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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)
Type Parameters
- T
The type of the objects in source
, constrained to XNode.
Parameters
- source
- IEnumerable<T>
An IEnumerable<T> of XNode that contains the source collection.
Returns
An IEnumerable<T> of XNode that contains all nodes in the source collection, sorted in document order.
Examples
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>
Remarks
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.