Here are my functions for conversion:
private function arrCol2XML(arrCol:ArrayCollection):XML
{
var xml:XML=new XML(<root></root>);
for (var i:Number=0; i<arrCol.length; i++)
{
var obj:Object=arrCol.getItemAt(i);
xml.appendChild(recursive(obj));
}
return xml;
}
private function recursive(obj:Object, str:String='item'):XML
{
var xml:XML=new XML('<' + str + '></' + str + '>' );
if(obj is Array)
{
for (var tmpObj:Object in obj)
{
Alert.show(flash.utils.getQualifiedClassName(tmpObj) + " - " + str);
// xml.appendChild(recursive(tmpObj as Object, 'item'));
}
} else {
for (var property:String in obj)
{
if(obj[property] is Array)
{
xml.appendChild(recursive(obj[property] as Array, property));
} else {
xml.appendChild(XML("<" + property + ">" + obj[property].toString() + "</" + property + ">"));
}
}
}
return xml;
}
Here is how I call them:
Alert.show(arrCol2XML(acRoute).toXMLString());
End here is my ArrayCollection:
objBlocat = {title:"Blocate", type:"nivel_blocat", children:[
{ title:"alege departament", type:"alege_departament", raspuns:'aaaa'}
]};
acRoute = new ArrayCollection([objIesire, objBlocat]);
And my output at current state of functions is:
<root>
<item>
<type>nivel_blocat</type>
<children/>
<mx_internal_uid>32F045BF-24B8-8AA8-3E8D-8F9BF92A0AFC</mx_internal_uid>
<title>Blocate</title>
</item>
</root>
And the alert:
int - children
Question: How can I solve this and is there a bug in the API?
PS: I admit the code isn't straight forward because it simply didn't work. PPS: SimpleXMLEncoder throws stack overflow if I have objects that have a property value referencing to other objects... so that's why I want to write my own method for the conversion Any help would be very appreciated! Many thanks!