Page 1 of 1

sorting xml nodes alphabatically

Posted: Sat Mar 14, 2009 5:55 am
by susrisha
is there any way i can sort the xml nodes list based on one of the attributes value?

Code: Select all

 
<node id="1" name="xyz">
<myvar>usa</myvar>
</node>
<node id="2" name="dsd">
<myvar>india</myvar>
</node>
......
 
i want to get the list sorted according to myvar..

i am right now using simplexml for parsing and getting the data.

Re: sorting xml nodes alphabatically

Posted: Sat Mar 14, 2009 6:21 am
by Benjamin
There is not a simpleXML method for sorting the data, however you can place them into a multidimensional array and sort that based on one of the values.

Re: sorting xml nodes alphabatically

Posted: Mon Mar 16, 2009 11:35 pm
by susrisha
The idea looks good .. but is there any other native class (like DOMXML) through which i can straight away sort the document based on the element value? I have written myself the function to sort things out but is there a better and easier way?
I have searched through google and found xsl is one of the solutions but it looks tedious to me. Any information is greately appreciated. :)