1 Reply Latest reply on Jul 1, 2011 2:03 AM by relaxatraja

    Importing multilevel XML

    badyani

      Hi guys, please help if you can, this is driving me crazy. I'm trying to import the following XML:

       

       

      <emails>
          <week>
           <vendor>Example1</vendor>
           <vendor>Example2</vendor>
          </week>
          <week>
           <vendor>Example3</vendor>
          </week>
          <week>
           <vendor>Example4</vendor>
          </week>
          <week>
           <vendor>Example5</vendor>
          </week>          
      </emails>

       

       

      and I'm using this code:

       

       

      emails = ArrayUtil.convertObjectToArray(a[i].emails.week);
      emailsNum = emails.length;
      var emailVendor: Array = new Array();
                
      for (var e: Number = 0; e < emailsNum; e++)
      {
           emailVendor[e] = emails[e].vendor;
      }

       

       

      The problem is that the number of weeks can vary, and the number of vendors per week can vary too. Any ideas? Please any help would greatly be appreciated.

      Thanks for looking!

        • 1. Re: Importing multilevel XML
          relaxatraja Level 5

          Read with two dimensional arrays:

           

          var dots:XML = new XML();
          dots.ignoreWhite=true;
          dots.load('test.xml');

          dots.onLoad = function(success:Boolean){
              if(success){
                  emailsNode=this.childNodes[0];
                  headerNode=emailsNode.childNodes.length;
                  var arr:Array=new Array();
                  for (i=0;i<headerNode;i++){
                      subNode=emailsNode.childNodes[i].childNodes.length;
                      arr[i]=new Array(subNode);
                      for (j=0;j<subNode;j++){
                          arr[i][j]=emailsNode.childNodes[i].childNodes[j].firstChild;
                          trace(emailsNode.childNodes[i].childNodes[j].firstChild);
                          trace("arr["+i+"]["+j+"]: "+ arr[i][j]);
                      }
                  }
              } else{
                  trace("Could not load XML");
              }
          }

           

          copy and paste the code you will get all the traces you want