2 Replies Latest reply on Mar 15, 2011 12:44 AM by Raghuvasa

    How to retrieve one level of xml only in a loop?

    Handycam Level 1

      I am processing this xml list:

      <item>
           <sponsor></sponsor>
           <itemName></itemName>
           <img></img>
           <description></description>
      </item>
      <item>
           <sponsor></sponsor>
           <itemName></itemName>
           <img></img>
           <description></description>
           <links>
                <link>
                     <thumb></thumb>
                     <url></url>
                     <caption></caption>
                </link>
                <link>
                     <thumb></thumb>
                     <url></url>
                     <caption></caption>
                </link>
           </links>
      </item>
      

       

      As you can see, only some item nodes have a links node and its related subnodes. 

       

      Originally, my application just had to loop through this collection and add all the "items" nodes to an array:

      for each ( var x:XML in myXMLList ) {
           var arr:Array = [];
           for each ( var y:String in x.children()){
                arr.push(y);
           } 
           bigArray.push(arr);
      }
      

       

      Worked fine.  But now I've gotten the rewuirement to handle this potential sub-node "<links>", and now this entire node, tags and all, is getting pushed into "arr".  How would I prevent that, and instead process each "link" node as its own entry in a NEW array?

       

      I am trying to prep this for JSON encoding, btw.  Ulimately I'm looking for:

       

      [ [sponsor,itemname,img,description] , [sponsor,itemname,img,description, [ [link1thumb,link1url,link1caption], [link2thumb,link2url,link2caption]  ]  ]