I have the following XML, which is generated by a 3rd-party library:
<PhoneNumbers>
<PhoneNumber Key="1">123-456-7890</PhoneNumber>
<PhoneNumber Key="2">234-567-8901</PhoneNumber>
<PhoneNumber Key="3">345-678-9012</PhoneNumber>
</PhoneNumbers>
The issue is that I should not depend on the values of the Key
attribute (a) appearing in order, or (b) beginning at 1. More so the latter, but I want this processing to be as safe as possible.
What I need to do is get a list of the phone numbers, sorted by the Key
value (ascending). So by using XmlNode.SelectNodes
I would like the resulting XmlNodeList
to contain the PhoneNumber
nodes in the proper order, not necessarily in the order they appear.
How can this be accomplished using XPath?
Is this possible to do directly?
If it makes a difference, I'm using .NET 2.0.