# Looping through nested XML

**URL:** https://forum.kirupa.com/t/looping-through-nested-xml/316460
**Category:** flash
**Created:** [November 22, 2010, 4:37pm UTC](https://forum.kirupa.com/t/looping-through-nested-xml/316460 "2010-11-22T16:37:44Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![patrickjv](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@patrickjv](https://forum.kirupa.com/u/patrickjv)
#### Post date: [November 22, 2010, 4:37pm UTC](https://forum.kirupa.com/t/looping-through-nested-xml/316460/1 "2010-11-22T16:37:44Z")

</div>

I got xml file more or less like below

```auto
 
<buttons>
 
 <button>
  <buttontext>Hello World</buttontext>
  <particles>
   <mindups>2</mindups>
   <maxdups>4</maxdups>
   <objcolor>[0xFF0000,0x00FF00]</objcolor>
   <mindur>12</mindur>
   <maxdur>36</maxdur>
  </particles>
 </button>
 
 <button>
  <buttontext>WHATS UP</buttontext>
 </button>
 
</buttons>

```

Some nodes do have the subnode, some don’t. All the nodes have one or more subnodes (it varies per button), the above is just an example that one buttons has a few defined (used to override default settings of a particle component)

I have so far read in all data and works fine, finally getting to the point of having to loop through the subnodes and process those which have been defined in each button… and now I have (simplified to bare)

```auto
 
  public var myBUT:XMLList;
 
myBUT = myXML.button;
var nr:uint = myBUT.length()
for(var j:uint = 0;j<nr;j++){
    if(String(myBUT[j].particles).length>0){
     set_particles(j)
    }
}
  function set_particles(j){
   var L:XMLList = myBUT[j].particles;
   for each (var n:XML in L) {
    trace(n)
   }
  }
 

```

where I had expected it to trace out 5 x (the subnodes) but it traces out 1x the whole node

```auto
 
<particles>
  <mindups>2</mindups>
  <maxdups>4</maxdups>
  <objcolor>[0xFF0000,0x00FF00]</objcolor>
  <mindur>12</mindur>
  <maxdur>36</maxdur>
</particles>
 

```

I’ve been staring at it for a bit now but got blanco … anybody see where I went off track??

P
