How do you specify node result order?
c#, sorting, xpath
Solution
Xpath itself does not define anything for that.
For C#.NET, this may be what you're looking for: http://social.msdn.microsoft.com/forums/en-US/xmlandnetfx/thread/ba975e0e-e0c7-4868-9acc-11d589cafc70/
Problem
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 it directly? If it makes a difference, I'm using .NET 2.0.