I have been modifying one of the Kirupa tutorials about loading external xml data and arrays. I have it successfully working, but i would like to figure out how to take it one step further. I want to be able to designate a each item in the arrays with an id rather than an iterative variable number and cannot figure out how to do it.
This is a snippet from the xml file:
<projects>
<item>
<id>13</id>
<projectname>First Project</projectname>
<location>Anytown, USA</location>
<units>60</units>
</item>
<item>
<id>33</id>
<projectname>Second Project</projectname>
<location>Sometown, USA</location>
<units>132</units>
</item>
</projects>
I am currently populating an array this way:
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
id* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
projectname* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
plocation* = xmlNode.childNodes*.childNodes[2].firstChild.nodeValue;
units* = xmlNode.childNodes*.childNodes[3].firstChild.nodeValue;
}
but that just gives me references to: projectname1, projectname2 etc.
I would like to figure out how to get the <id> value from the loaded xml file connected to the variable name of each item in the array so that i can refer to the variables this way: projectname13, projectname33, etc.
Does this make sense? Can anyone help?