Friday, March 26, 2010

Convert String to XMLListCollection

Hi,

I have a XMLLIstCollection and I coverted the XMLLIstCollection to String(XMLLIstCollection.toString()) and send it to database. Similarky, I would like to receive the stored string value from the database and show it in Tree. For this, I am trying to convert the String to XMLListCollection(StringVariable as XMLListCollection) and it has null value.

It it possible to typecast/convert a String to XMLListCollection?

Thanks!

Convert String to XMLListCollection

This example answers your question. Note how I cast the string to an XMLList, and then use e4x syntax to extract the XML data to populate the XMLListCollection.

If this post answers your question or helps, please mark it as such.

%26lt;?xml version=''1.0'' encoding=''utf-8''?%26gt;
%26lt;mx:Application xmlns:mx=''http://www.adobe.com/2006/mxml''
?creationComplete=''init();''%26gt;
?%26lt;mx:Script%26gt;
?%26lt;![CDATA[
?import mx.collections.XMLListCollection;
?private var strXML:String = ''%26lt;myData%26gt;%26lt;item%26gt;%26lt;fname%26gt;Bob%26lt;/fname%26gt;%26lt;lname%26gt;Smith%26lt;/lname%26gt;%26lt;/item%26gt;%26lt;item%26gt;%26lt;fname%26gt;Tim%26lt;/f name%26gt;%26lt;lname%26gt;Carson%26lt;/lname%26gt;%26lt;/item%26gt;%26lt;item%26gt;%26lt;fname%26gt;Jon%26lt;/fname%26gt;%26lt;lname%26gt;Casey%26lt;/lname%26gt;%26lt;/i tem%26gt;%26lt;/myData%26gt;'';
?[Bindable] private var xlc:XMLListCollection;
?
?private function init():void{
?xlc = new XMLListCollection(XMLList(strXML)..item);
?}
?]]%26gt;
?%26lt;/mx:Script%26gt;
?%26lt;mx:DataGrid dataProvider=''{xlc}''%26gt;
?%26lt;mx:columns%26gt;
?%26lt;mx:DataGridColumn dataField=''fname''/%26gt;
?%26lt;mx:DataGridColumn dataField=''lname''/%26gt;
?%26lt;/mx:columns%26gt;
?%26lt;/mx:DataGrid%26gt;
%26lt;/mx:Application%26gt;

No comments:

Post a Comment