1 Reply Latest reply on Jun 15, 2009 2:04 PM by rgadiparthi

    Help with xmlListCollection and getItemAt method!




        I have a simple application in which I have a data grid, http sevice and xmllistcollection. I get the xml data and populate the xmllistcollection. Objective is to traverse the xmlcollection to get the first row, parse and set the column headers dynamically.


      the first row in the xmllistcollection are the column headers. I am trying to get the values using the getItemAt(0) method, which does return a object but not sure how to traverse the object to draw the column headers for the data grid dynamically? below is the sample example


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

         import mx.collections.ArrayCollection;
         import mx.rpc.events.ResultEvent;
         import mx.rpc.events.FaultEvent;
         import mx.controls.Alert;
         import mx.controls.dataGridClasses.DataGridColumn;

                public function fetch():void
            var i:int = 0;     
            var a:XMLList = new XMLList(xdata.getItemAt(0).toString() as XMLList); 
           Alert.show(a.text() + "a");
           for each(var xml:XML in a)
             Alert.show("I am inside" + i);
             var attributes:XMLList = xml.attributes();
             var o:Object = new Object();
             for each (var attribute:XML in attributes)
              Alert.show("I am  way inside" + i);
              var nodeName:String = attribute.name().toString();
              var value:*;
              value = attribute.toString();
                 i = i+1;   


          <mx:HTTPService result="handleXMLnew(event);" fault="handleFault(event);" id="xmlRPC" resultFormat="e4x"
          url="http://abc/Xcelsius/swat/RCD.xsql" useProxy="false">
      <mx:XMLListCollection id="xdata" source="{xmlRPC.lastResult.ROW}"/>
      <mx:DataGrid dataProvider="{xdata}" x="24" y="110" id="adg1" width="694" height="168"/>
      <mx:Button x="653" y="44" label="Go" click="fetch();"/>