I'm looking for an efficient and reusable way to parse xml into an object in actionscript2. The xml structure itself might change so it's important that im able to parse the xml with out 'hard coding' specific nodes, etc.
I normally use As3 and wouldn't need something like this since the XML class is easy to drill down into. Below is AS3 pseudocode of what I'm trying to accomplish.
public function XmlObject(myXmlObject:XML,_node:String):Object
{
var xmlObj:Object=new Object();
for(var node:uint=0;node<myXmlObject[_node].children().length();node++)
{
var attributesList:XMLList=myXmlObject[_node].children()[node].attributes();
var nodeName:String=myXmlObject[_node].children()[node].name();
switch(attributesList.length()>1)
{
//////////////////////
case false:
//////////////////////
{
for each(var attribute:XML in attributesList)
{
xmlObj[nodeName]=attribute;
}
break;
//////////////////////
case true:
//////////////////////
var values:Array=[];
for each(attribute in attributesList)
{
values.push(attribute);
xmlObj[nodeName][String(attribute.name())]=attribute;
}
break;
}
}
return xmlObj;
}
Thanks in advance for any help on this!