How to sort XML


i have xml this:

 

<node label="california">

     <node label="location 1" />

     <node label="location 2">

          <node label="option 1" />

          <node label="option 2" />

     </node>

</node>

<node label="oregon">

     <node label="portland" />

</node>

 

 

i'm using xml data provider astra tree component (http://developer.yahoo.com/flash/astra-flash/tree/) want sort each node , each child node in alpha order , i'm trying figure out best way go it.

 

i've found code sorts xmllists:

 

function sortxmllist(list:xmllist, fieldname:object, options:object = null):xmllist {

          var i:int;

          var arr:array = new array();

          var ch:xml;

          for each (ch in list) {

                    arr.push(ch);

          }

 

 

          var resultarr:array = [];

 

 

          if (fieldname == null && options == null) {

                    resultarr = arr.sort();

          } else if (fieldname==null) {

                    resultarr = arr.sort(options);

          } else {

                    resultarr = arr.sorton(fieldname,options);

          }

 

 

          var result:xmllist = new xmllist();

 

 

          for(i=0; i<resultarr.length; i++){;

          result += xml(resultarr[i]);

}

return result;

}

 

but doesn't work directly on xml , i'm having hard time figuring out how go through levels (the sample above has three, final xml might have more nested levels) , sort in alpha order.

 

any ideas?

never mind — sort of....

 

i changed how xml object being generated , sorted in alpha order.

 

but question still hangs out there. there "easy" way sort xml , children (and children) specific order?



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

PProHeadless.exe has stopped working error when opening projects in Adobe Media Encoder CS6

Preconditions Failed. - Joomla! Forum - community, help and support