Is there a way we can sort xmlnodes based on attribute values, consider I can\'t use linq. Since I\'m using .NET 2.0.
Example:
To sort use following:
var xml= xDoc.Element("Root")
.Elements("I")
.OrderByDescending(s => (int) s.Attribute("aa"));
Then to save it:
XDocument doc = new XDocument(new XElement("Root", xml));
doc.Save("C:\\Something.xml");
UPDATE
You can use XSLT for this:
And invoke it (quoting How to apply an XSLT Stylesheet in C# ):
XPathDocument myXPathDoc = new XPathDocument(myXmlFile) ;
XslTransform myXslTrans = new XslTransform() ;
myXslTrans.Load(myStyleSheet);
XmlTextWriter myWriter = new XmlTextWriter("result.xml",null) ;
myXslTrans.Transform(myXPathDoc,null,myWriter) ;