So you have a third-party web service that likes to abuse XML and return things in an order that makes your programming a complete pain in the neck. For example…
<file> <node1>Foo</node1> <price>4.99</price> <node2> <key>XX999</key> </node2> </file>
There are about a thousand of these sorted in order by price.
How can you re-sort this XML document by the key value?
I need the result to be a sorted XML file. Thanks!
EDIT: .NET version 2.0 (no LINQ)
Here’s how to do it with XSLT:
assuming your data takes this form (file.xml):
This transform (stylesheet.xsl):
When used with this .Net code (need to add a
using System.Xml;):Results in this output in sorted.xml: