1 Reply Latest reply on Aug 7, 2009 5:28 AM by Gregory Lafrance

    Convert String to XMLListCollection

    hclselvs Level 1

      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!

        • 1. Re: Convert String to XMLListCollection
          Gregory Lafrance Level 6

          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.

           

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