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
Post a Comment