4 Replies Latest reply on Nov 9, 2007 7:37 PM by ntsiii

    Generating Array collection from xml over http

      Hi all,

      I am accessing an xml using an httpservice component and populating a datagrid.I could do that.What I am unable to do is assign the result of this request to an array collection since populating datagrid through array collection would make it easier for sorting,filtering ,bla blabla.Heres the code.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="xyz.send();abc.send();kdp.send();">

      <mx:HTTPService id="xyz" url=" http://localhost:8080/books.xml" resultFormat="object"/>
      <mx:HTTPService id="abc" url=" http://localhost:8080/books.xml" resultFormat="e4x" />
      <mx:HTTPService id="kdp" url=" http://localhost:8080/books.xml" resultFormat="array"/>

      import mx.utils.*;
      import mx.utils.*;
      import mx.collections.*;
      import flash.display.Sprite;

      //public var booklistArray:Array=new Array(xyz.lastResult.catalog.book);
      //public var booklistXmllist:XMLList=new XMLList(xyz.lastResult.catalog.book);
      public var booklist_arraycollection:ArrayCollection=new ArrayCollection(booklistArray);
      public var booklist_ac :ArrayCollection;


      <mx:XMLListCollection id="booklist_tree" source="{abc.lastResult.book}" />
      <mx:XMLListCollection id="authorlist_combo" source="{abc.lastResult.book.author}" />
      <!--mx:ArrayCollection id="booklist_grid" source="{xyz.lastResult.catalog}" /-->

      <mx:Panel title="Dataview" >
      <mx:HDividedBox width="1200" height="300">
      <mx:DataGrid x="10" width="50%" height="100%" dataProvider="{xyz.lastResult.catalog.book}" />
      <mx:DataGrid x="10" width="50%" height="100%" dataProvider="{mx.utils.ArrayUtil.toArray(kdp.lastResult.catalog.book)}" />

      You could use any xml and try it out.MAYBe,there might be some typos/bugs since I shortened the code and just presented the grids.

      You can see that the first grid with it dataprovider as 'xyz.lastResult.catalog.book' works just fine but I would like to convert the httpservice result into an array collection and then pass that on which I am unable to do.

      xml structure :
      <a bunch of book nodes>