I had already referred this following link but could not find the solution for my scenario.
Actionscript 3 - How can i convert from XMLList to XML?
My xml variable is as follows:
private var checkXml:XML = new XML(
<universe>
<item name="cat 2">
<item name = "All"/>
<item name = "item 1"/>
<item name = "item 2"/>
</item>
<item name="cat 2">
<item name = "All"/>
<item name = "item 3"/>
<item name = "item 4"/>
<item name = "item 5"/>
<item name = "item 5"/>
</item>
<item name="cat 3">
<item name = "All 33"/>
<item name = "item 34"/>
<item name = "item 44"/>
</item>
</universe>);
I use a filter function to remove the duplicate values in above xml as:
private function filter(xmlSample:XML):XMLList
{
var seen:Object={};
return xmlSample..@name.(!seen[valueOf()]&&(seen[valueOf()]=true));
}
which returns XMLList data.When I use this to get an XML format as:
var thisXml:XMLList = filter(checkXml);
Alert.show(thisXml.toXMLString());
I do not get the output in XML format;I get it this way.:
cat 2
All
item 1
item 2
item 3
item 4
item 5
cat 3
All 33
item 34
item 44
How to get the same in XML format in Flex like that of my XML variable "checkXml".,so that I can retain all the parent nodes and child nodes as it is thereby the duplicates getting removed.


Here's a quick suggetion:
With the basic xml you have it does the job, but it's not very flexible. It should merge child nodes for duplicates and perhaps should be recursive, but I've got no time atm.
Update: I've got two more versions for you. One that goes into the child nodes a level:
so an xml like this:
produces an output like this:
Note that attributes in the root node are lost if any. Probably the best option is still to use recursion, like so:
I'm not sure if this is the cleanest/most elegant solution, but it works:
produces:
Notice nodes with the same names got collapsed recursively (like "All" and "item child 3"), but unfortunately the node order the way a bit.