Extensions.InDocumentOrder(Of T) Method (IEnumerable(Of T))

 

Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Namespace:   System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)

<ExtensionAttribute>
Public Shared Function InDocumentOrder(Of T As XNode) (
	source As IEnumerable(Of T)
) As IEnumerable(Of T)

Parameters

source
Type: System.Collections.Generic.IEnumerable(Of T)

An IEnumerable(Of T) of XNode that contains the source collection.

Return Value

Type: System.Collections.Generic.IEnumerable(Of T)

An IEnumerable(Of T) of XNode that contains all nodes in the source collection, sorted in document order.

Type Parameters

T

The type of the objects in source, constrained to XNode.

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.

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.


                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>

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: