3 Replies Latest reply on Jan 27, 2009 9:01 AM by ntsiii

    DataGrid and XML

    nihaopaul Level 1
      Hi,

      I have XML returning from a web service going into a data grid. I can't change the data at the server end so I need to change some values in the xml data before it's loaded into the data grid. How do I do that? Any help appreciated.

      Thanks,

      Paul

        • 1. DataGrid and XML
          levancho Level 3
          dont bind the result of the service directly to the datagrid,
          instead (one way of doing it : )
          1) bind a variable (some kind of Collection type) to datagrids' dataprovider,

          2) register a listener to service and when you get data you can do whatever you want with it and then set it as value of the variable from step 1) t and violla datagrid will update magically :)
          • 2. Re: DataGrid and XML
            nihaopaul Level 1
            Hi,

            Thanks for your help.

            Originally the data grid had: dataProvider="{myHTTPDetail.lastResult.dict.item}" which works fine and I get the xml data back and it fills the data grid.

            Then, to see if it would work before tweeking the returned data I tried:-

            [Bindable]
            private var xml:XML;
            -----
            private function handleComplete(event:Event):void
            {
            xml = new XML(this.loader.data);
            dgDict.dataProvider = xml.dict.item;
            }

            But this is no-go. How do I get the data from my variable xml into the data grid? In the debugger the data is there. Any help appreciated.

            Regards,

            Paul

            • 3. Re: DataGrid and XML
              ntsiii Level 3
              Are you using HTTPService?
              Have you set resultFormat="e4x"
              The argument in the handler should be "ResultEvent"
              As levancho suggests, create a[Bindable] instance level variable typed as XMLListCollection, bind the DG to that
              in the handler do:
              var xml:XML = XML(event.result);
              trace(xml.toXMLString()); //verify the xml data
              var xlItems:XMLList = xml.dict.item;
              trace(xlItems.toXMLString()); //verify the xmlList data
              _xlcItems = new XMLListCollection(xlItems);

              Adjust the DataGridcolumns for the observed data structure. Use"@" for attributes.