Public Function SortNodes(ByRef voRoot As IXMLDOMNode, ByRef vsPath As String, ByRef vsSortBy As String) As IXMLDOMNode
Dim oNode As IXMLDOMNode
Dim oPlace As IXMLDOMNode
Dim oClone As IXMLDOMNode
On Local Error GoTo Handler
If Not Nothing Is voRoot Then
Set SortNodes = voRoot.cloneNode(True)
For Each oNode In SortNodes.selectNodes(vsPath)
Set oPlace = oNode
Do Until Nothing Is oPlace.previousSibling
Set oPlace = oPlace.previousSibling
Loop
Do
If Nothing Is oPlace Then
Set oPlace = oNode.parentNode
oPlace.removeChild oNode
oPlace.appendChild oNode
Exit Do
ElseIf oNode.selectSingleNode(vsSortBy).Text < oPlace.selectSingleNode(vsSortBy).Text Then
oPlace.parentNode.removeChild oNode
oPlace.parentNode.insertBefore oNode, oPlace
Exit Do
End If
Set oPlace = oPlace.nextSibling
Loop
Next oNode
End If
Exit Function