# Easy XML Loop question

**URL:** <https://forum.kirupa.com/t/easy-xml-loop-question/251466>\
**Category:** flash\
**Created:** [February 8, 2008, 7:50pm UTC](https://forum.kirupa.com/t/easy-xml-loop-question/251466 "2008-02-08T19:50:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![No\_44](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@No\_44](https://forum.kirupa.com/u/No_44)\
**Post date:** [February 8, 2008, 7:50pm UTC](https://forum.kirupa.com/t/easy-xml-loop-question/251466/1 "2008-02-08T19:50:11Z")

</div>

Hello all,

I had a quick question regarding how to loop through an Object and build a formatted XML trace with the results. I think I am just missing something really small here.

In the below case, the code is supposed to loop through the object and retrieve 4 attributes.

Here is my current code:

```auto
 
on(press) {
 var my_xml2 = new XML();
 my_xml2.xmlDecl = "<?xml version=\"1.0\" ?>";
 var node = my_xml2.createElement("myclassroom"); 
 my_xml2.appendChild(node);
 node = my_xml.createElement("furniture"); 
 my_xml2.firstChild.appendChild(node);
 for (var prop in _root.itemList){
 node = my_xml2.createElement("fixture");
 my_xml2.firstChild.firstChild.appendChild(node);
 my_xml2.firstChild.firstChild.firstChild.attributes.rotation = _root.itemList[prop]._rotation;; 
 my_xml2.firstChild.firstChild.firstChild.attributes.yCoord = _root.itemList[prop]._y;
 my_xml2.firstChild.firstChild.firstChild.attributes.xCoord = _root.itemList[prop]._x;
 my_xml2.firstChild.firstChild.firstChild.attributes.ftype = _root.itemList[prop].ftype;
 
 }
 trace(my_xml2);
}

```

And here are the results:

```auto
<?xml version="1.0" ?><myclassroom><furniture><fixture ftype="1" xCoord="450" yCoord="150" rotation="test" /><fixture /><fixture /><fixture /><fixture /><fixture /><fixture /><fixture /><fixture /></furniture></myclassroom>

```

So when looping, flash gets the first set of 4 attributes and displays them beautifully. Then it correctly shows the correct number of tags that are supposed to be there, but the attributes are blank.

If I do a:

```auto
trace(_root.itemList[prop].ftype);

```

all of the names show correctly.

Can anyone see anything wrong with that code?

Thanks in advance for any pointers!

44
