views:

80

answers:

1

I want to set reverse order of child nodes of given XML nodes.

How to do this???

 <Parent>
   <Child1>  </Child1>
   <Child2>  </Child2>
 </Parent>

OUTPUT:

<Parent>
<Child2>  </Child2>
<Child1>  </Child1>
</Parent>

EDIT: I have simple XML file like above.

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(value);
XmlElement docElement = xmlDoc.DocumentElement;

I just want this XmlElement in reverse order.

NOTE: I am using VS-2008 2.0

+2  A: 

If you are using C#3 / NET 3.5 then you can use LinqToXml and something like this:

XDocument xdoc = XDocument.Load(Server.MapPath("data.xml"));
var reversed = xdoc.Descendants("Parent").Descendants().Reverse();
Dan Diplo
This was going to be my exact same suggestion!
alastairs