In a Flex webapp, is there an easy way to go about applying a sort to the children of an XML element, based on the children's attributes? Example follows below:
XMLListCollection:
<a anotherProp="ABCDE">
<e prop="AB">1</element>
<e prop="BC">2</element>
</a>
<a anotherProp="FGEH">
<e prop="HF">3</element>
<e prop="AD">4</element>
<e prop="AC">5</element>
</a>
I would like to sort the <e>
elements, within each <a>
element separately, according to their "prop" attribute. My code for generating the array containing the <a>
elements is along the lines of:
for each(var node:XML in initialInput:XMLListCollection){
if(node.localName()=="a"){
//I was hoping to be able to sort the <e> children of the node variable here
xmlListCollectionVar.addItem(node);
}
}
At the end I would like the <a>
's to remain in their defined order, but their <e>
children to be sorted based on the "prop" attribute. So far if I try:
node.children().sort=someSortVar
where someSortVar has its fields set to:
SortFields("e.@prop",...)
I get an exception about a null value. Any way to convert the children list to XMLListCollection, sort it and integrate it back into the node variable? Thanks for any replies.