Posts

Showing posts from July, 2011

Convert XML to ArrayCollection

If you have an XML and want to use it in the spark's list component, than you need to first convert it into ArrayCollection and that's what we are doing in this example:

Lets assume you have following XML:

varstrXML:XML = <blog>
<item>
              <title>Blog by Subodh Gupta
<author>Subodh Guptaauthor>
</item>
</blog>;




var xml:XML = new XML(strXML);
var xmlDoc:XMLDocument = new XMLDocument(xml);
var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
var resultObj:Object = decoder.decodeXML(xmlDoc);
var ac:ArrayCollection ;

if(resultObj.blog.hasOwnProperty("item")) {
      if(resultObj.blog.item is ArrayCollection)
      {
      ac = resultObj.root.element;
}
}

that's it you are done. Cheers.