2 Replies Latest reply on Jul 7, 2008 11:06 AM by ntsiii

    Multiple XML in one XML

    DevShri
      Inside the function LoadData(e:Event): I am trying to add every XML object into userData xml. So that I can create the dataProvider of whole data for my datagrid. But I am still not able to do that.
      Please help.

      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="init()" >
      <mx:Script >
      <![CDATA[
      import mx.controls.List;


      import flash.net.URLLoader;
      import mx.controls.Alert;


      [Bindable] var xmlLoader:URLLoader = new URLLoader();
      [Bindable] var xmlD:URLLoader = new URLLoader();
      [Bindable] var xmlData:XML = new XML();
      [Bindable] var userData:XML = new XML();
      [Bindable] var userTotal:XMLList = new XMLList();

      public function init():void{
      xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
      xmlLoader.load(new URLRequest(" http://10.21.116.103:8080/UserApp/resources/ncbuusers/"));

      }


      public function LoadXML(e:Event):void {

      xmlData = new XML(e.target.data);

      ParseUsers(xmlData);

      }

      function ParseUsers(userXML:XML):void {

      var newsList:XMLList = userXML.children();

      for each (var newsTitle:XML in newsList) {
      var aString:String = newsTitle.@uri;
      // xmlD.addEventListener(Event.COMPLETE, LoadData);
      xmlD.load(new URLRequest(aString));
      userData.prependChild(new XML(xmlD.load(new URLRequest(aString))));


      }
      function LoadData(e:Event):void {

      userData.appendChild(new XML(e.target.data));

      //aList.addItem(userData);
      }
      }
      ]]>

      </mx:Script>
      <mx:HBox id="hb">

      <mx:Panel title="Users" height="100%" width="100%">

      <mx:DataGrid id="dGrid" dataProvider="{userData}">
      <mx:columns>
      <mx:DataGridColumn dataField="city" headerText="City" />
      <mx:DataGridColumn dataField="country" headerText="Country" />
      <mx:DataGridColumn dataField="companygroup" headerText="Company Group" />
      <mx:DataGridColumn dataField="email" headerText="Email" />
      <mx:DataGridColumn dataField="givenname" headerText="Given Name" />
      <mx:DataGridColumn dataField="phone" headerText="Phone" />
      <mx:DataGridColumn dataField="role" headerText="Role" />
      <mx:DataGridColumn dataField="site" headerText="Site" />
      <mx:DataGridColumn dataField="uid" headerText="UID" />
      <mx:DataGridColumn dataField="zipcode" headerText="Zipcode" />

      </mx:columns>
      </mx:DataGrid>
      </mx:Panel>

      </mx:HBox>

      </mx:Application>
        • 1. Re: Multiple XML in one XML
          Gregory Lafrance Level 6
          Your url did not work for me, so could you please post sample data. Please post the sample data for the first loader call, and also for the second loader calls for user uris.
          • 2. Re: Multiple XML in one XML
            ntsiii Level 3
            First, you never use "new" with XML, as that is not a constructor, but a top-level function.

            Second, all data service calls are asynchronous, so you can never access the result in the same function in which you invoke the call. the code in your loop is a mess, I assume you were just trying stuff. You were closer with the event listener, that is the only way to do it.

            Tracy