PDA

View Full Version : Loop through XML to create arrays


yoogie8
07-04-2005, 08:06 PM
I'm having trouble looping through my xml doc to create arrays to use the variables to make a menu:

<menu>
<title>New Menu</title>
<item>
<text>Menu item 1</text>
<link>newsletter.php?nlID=1</link>
</item>
<item>
<text>Menu item 2</text>
<link>newsletter.php?nlID=2</link>
</item>
</menu>

function myOnLoad() {
var newsletters = this.childNodes[0].childNodes[0].nextSibling;
var menu = newArray();
menu = newsletters.childNodes[0].childNodes[0];
var link = newArray();
link = newsletters.childNodes[1].childNodes[0];
}

How do I loop through the xml to assign variables to the 'menu' and 'link' arrays?

mambenanje
07-04-2005, 08:22 PM
for(i=0;i<xml.childNodes.length;i++){
mymenu= new Object();
menu= new Array();
mymenu.text=xml.childNodes[i].childNodes[0].firstChild.nodevalue;
mymenu.link=xm.childNodes[i].childNodes[1].firstChild.nodevalue;
menu[i]=mymenu;
//or menu.push(mymenu)
}

just give it a try I think this one will give you an idea

yoogie8
07-04-2005, 09:02 PM
Thanks mambenanje, that takes me one step closer... :?)