tesmc
asked on
XML: how to sort a dom by attribute
I have the following input xml that I want to sort by /root/Traveler/@Type
I'm not concerned with ordering of the LastName or FirstName, precedence is attribute Type.
Expected result:
I had tried doing the below but it did not always worked, it seems to have taken into account the TravlerName
var nodeComplete = domReq.Root.SelectSingle(" CompletePN RElements" );
domReq.SortNodes(nodeCompl ete, "Traveler", "@Type", "XMLDOM_SORT_ASCENDING");
I'm not concerned with ordering of the LastName or FirstName, precedence is attribute Type.
<root>
<Traveler Type="ADT" AscID="T1">
<TravelerName>
<LastName>DUFFY</LastName>
<FirstName>SELENA</FirstName>
</TravelerName>
</Traveler>
<Traveler AscID="T2" Type="CNN">
<TravelerName>
<LastName>DUFFY</LastName>
<FirstName>RACHAEL</FirstName>
</TravelerName>
</Traveler>
<Traveler AscID="T3" Type="CNN">
<TravelerName>
<LastName>DUFFY</LastName>
<FirstName>ANDREW</FirstName>
</TravelerName>
</Traveler>
<Traveler AscID="T4" Type="ADT">
<TravelerName>
<LastName>DUFFY</LastName>
<FirstName>SALMA</FirstName>
</TravelerName>
<Infant AscID="T4.1" Type="INF">
<LastName>DUFFY</LastName>
<FirstName>BABY</FirstName>
</Infant>
</Traveler>
</root>
Expected result:
<root>
<Traveler Type="ADT" AscID="T1">
<TravelerName>
<LastName>DUFFY</LastName>
<FirstName>SELENA</FirstName>
</TravelerName>
</Traveler>
<Traveler AscID="T4" Type="ADT">
<TravelerName>
<LastName>DUFFY</LastName>
<FirstName>SALMA</FirstName>
</TravelerName>
<Infant AscID="T4.1" Type="INF">
<LastName>DUFFY</LastName>
<FirstName>BABY</FirstName>
</Infant>
</Traveler>
<Traveler AscID="T2" Type="CNN">
<TravelerName>
<LastName>DUFFY</LastName>
<FirstName>RACHAEL</FirstName>
</TravelerName>
</Traveler>
<Traveler AscID="T3" Type="CNN">
<TravelerName>
<LastName>DUFFY</LastName>
<FirstName>ANDREW</FirstName>
</TravelerName>
</Traveler>
</root>
I had tried doing the below but it did not always worked, it seems to have taken into account the TravlerName
var nodeComplete = domReq.Root.SelectSingle("
domReq.SortNodes(nodeCompl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@leakim971
thank you. i had my attribute reference incorrect but once i did as you noted "./@Type" it worked.
appreciate it.
thank you. i had my attribute reference incorrect but once i did as you noted "./@Type" it worked.
appreciate it.
ASKER
var nodeComplete = domReq.Root.SelectSingle("
domReq.SortNodes(nodeCompl
would you have another suggestion?