# Loop through xml

**URL:** <https://forum.kirupa.com/t/loop-through-xml/174198>\
**Category:** Uncategorized\
**Created:** [January 3, 2006, 6:27pm UTC](https://forum.kirupa.com/t/loop-through-xml/174198 "2006-01-03T18:27:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakepeg](https://avatars.discourse-cdn.com/v4/letter/j/8dc957/32.png) [@jakepeg](https://forum.kirupa.com/u/jakepeg)\
**Post date:** [January 3, 2006, 6:27pm UTC](https://forum.kirupa.com/t/loop-through-xml/174198/1 "2006-01-03T18:27:43Z")

</div>

hi.

I want to loop through xml adding each node to a new xml object and to check the id attribute and if its a certain id then add in an extra node.

here is the original xml…

\<folder id=“98592” label=“Banks Online” displayname=“Banks Online”\>  
\<folder id=“98593” label=“Barclays” displayname=“Barclays”\>  
\<folder id=“98594” label=“Business” displayname=“Business”\>  
\<folder id=“98598” label=“Personal” displayname=“Personal”\>  
\</folder\>  
\</folder\>  
\<folder id=“98705” label=“Fund Managers” displayname=“Fund Managers”\>  
\<folder id=“98706” label=“Barclays” displayname=“Barclays”\>  
\</folder\>  
\<folder id=“99013” label=“Stock Markets” displayname=“Stock Markets”\>

the xml to be added is like this…

\<folder id="-10" label=“asdasd” displayname=“asdasd” /\>

and the code would be sum’t like this…

[AS]var parent\_id = “98598”;  
for(var i = 0; i \< myXML.length; i++) {  
newerXML += myXML.childNodes\*  
if (myXML.childNodes\*.attributes.id == parent\_id) {  
newerXML += append\_xml;  
}  
}[/AS]

but its not working. any thoughts?
