PDA

Click to See Complete Forum and Search --> : reading in dynamic XML and using recursive functions



Squirtle
05-22-2001, 12:23 AM
Hi,

I am trying to read in an XML that looks like this:



< directoryTree >
< root >
< child >
upload
< child >new< / child >
< child >bin< / child >
< / child >
< child >
new
< child >
images
< child >
new
< child >april< / child >
< child >may
< child >birthday< / child >
< / child >
< / child >
< / child >
< / child >
< child >
music
< child >greenday< / child >
< / child >
< / root >
< / directoryTree >




Where the node values will change everytime I load it into the flash file, as well as the amount of nodes. (i.e. this is just an example)

Excuse the spaces between tags, for some reason I can't get it to show any other way.............:P (I have enough things not working today)

Here is my code. I am recursivly calling the same funciton but for some reason it won't read the child nodes. See below:



folderXML = new XML;
folderXML.onLoad = convertXML;
display = "Loading data...";
folderXML.load("dir.xml");



function convertXML () {
if (this.loaded) {
display = "Data Loaded";
}

dirTag = new XML;
dirTag = this.firstChild;
dirArray = new Array;
dirArray = dirTag.childNodes;

for (k=0; k < dirArray.length; k++) {
processTag(dirArray[k]);
}
}



function processTag (tag) {
tagXML = new XML;
tagArray = new Array;

tagXML = tag;
tagArray = tagXML.childNodes;

for (j=0; j < tagArray.length; j++) {
if (tagArray[j].nodeName != null && tagArray[j].nodeName != "") {
processTag(tagArray[j]);

}
}
}



Even another example of this been done would be appreciated. I have looked through the boards and movies to no avail (unless I have missed something)

Thanks.....

tic
05-22-2001, 12:29 AM
don't be like that :(

Astuce
05-22-2001, 12:32 AM
Originally posted by tic
don't be like that :(


Ne sois pas comme ca.

No estas como aqui.

Squirtle
05-22-2001, 02:15 AM
Any *serious* replys would be useful as well. *smile*

FlashGuru
05-22-2001, 06:13 AM
Hey man try this, ive changed a few variable names and wrote the code in my own way, but it does the same thing:



myxml=new XML()
myxml.onLoad=parse
myxml.load("dir.xml")
display="Loading Data...."

function parse(loaded){
if(loaded){
myxml=myxml.firstChild
if(myxml.hasChildNodes()){
var kids=myxml.childNodes
for(var z=0;z&lt;kids.length;++z){
if(kids[z].nodeName != null && kids[z].nodeName != ""){
recurse(kids[z])
}
}
}
}
}

function recurse(node){
if(node.hasChildNodes()){
var kids=node.childNodes
for(var z=0;z&lt;kids.length;++z){
recurse(kids[z])
}
}
}
[Edited by FlashGuru on 05-22-2001 at 06:28 AM]

Squirtle
05-22-2001, 07:18 PM
That was exactly what I needed.
:PPPPPPP