Extensions.InDocumentOrder(Of T) Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
'Declaration <ExtensionAttribute> _ Public Shared 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
- 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.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable(Of T). When you use instance method syntax to call this method, omit the first parameter.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 output As New StringBuilder 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 output.Append(el) output.Append(Environment.NewLine) Next OutputTextBlock.Text = output.ToString()
Show: