I am loading an xml and looping through it using a recursive function. The problem is that it only reads through the first tree and then quits…??
XML:
<root id="0">
<dir id="1" name="Lounge,_Chillout">
<dir id="2" name="Opera_Chillout_2003">
<dir id="3" name="CD1">
<pl>1e00ad1d-66ba-4496-8168-0d926422739c.xml</pl>
<tn>15</tn>
</dir>
<dir id="4" name="CD2">
<pl>47c5dc51-e0d6-4b5e-a837-76a18600fcd6.xml</pl>
<tn>14</tn>
</dir>
</dir>
<dir id="5" name="Roger_Sanchez_-_First_Contact">
<pl>9c5eb7bf-9a0d-45e9-8e51-b2acccd66b17.xml</pl>
<tn>9</tn>
</dir>
<dir id="6" name="Royksopp_-_Melody_a.m">
<pl>7cbb66fd-2d33-427a-8627-cce502ee14b8.xml</pl>
<tn>10</tn>
</dir>
<dir id="7" name="Secret_Garden_-_Songs_from_a_Secret_Garden">
<pl>607bf25e-c1a1-4660-9b8b-0bf4731ae61a.xml</pl>
<tn>12</tn>
</dir>
</dir>
<dir id="8" name="Soundtracks">
<dir id="9" name="Army_Of_Darkness">
<pl>991a68ac-1be2-4201-b3ed-65d341e8134d.xml</pl>
<tn>21</tn>
</dir>
<dir id="10" name="Soundtrack_-_Reservoir_Dogs" />
</dir>
</root>
Actionscript:
loadXml = function (filename) {
summaryXml = new XML();
summaryXml.ignoreWhite = true;
summaryXml.load("xmls/"+filename+".xml");
summaryXml.onLoad = function(success) {
if (success) {
getDirs(summaryXml,6);
}
};
getDirs = function(xml, id)
{
currentNodes = xml.childNodes;
for (var i=0; i< currentNodes.length; i++) {
if (currentNodes*.attributes.id == id) {
trace("bingo @ " + currentNodes*.attributes.name);
} else {
if (currentNodes*.hasChildNodes()) {
trace("search goes on @ id: " + currentNodes*.attributes.name);
getDirs(currentNodes*, id)
}
else
{
trace("no more childs");
}
}
}
};
the result is:
search goes on @ id: undefined
search goes on @ id: Lounge,_Chillout
search goes on @ id: Opera_Chillout_2003
search goes on @ id: CD1
search goes on @ id: undefined
no more childs
I found a similar problem in another thread. i tried the solution from that thread but it didn’t solve my problem…
Does anyone have an idea?