- Forum
- General Help
- XML
- [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] recursion and parsing X
-
working code
Any XML will do. Its working code. You just have to set the root XML node to parse from. Example:
Code:
//
x = 0;
//
//
function doXML(whichXML, x, nodePass) {
while (whichXML[x].hasChildNodes) {
// error correction
whichXML[x].ignoreWhite = true;
if (String(whichXML[x].nodeName) == "null" ) {
whichXML[x].removeNode();
}
// the meat
this[v] = whichXML[x].childNodes[0].nodeValue;
v = string(nodePass+whichXML[x].nodeName+"_"+(x));
// recurse
doXML(whichXML[x].childNodes, 0, string(v+"."));
x++;
}
}
// set the root node here.
theXML = theXML.childNodes[2].childNodes;
//
doXML(theXML, 0, "");
The number i'm refering to is v . The function should parse through each subtree starting at 1 for each node name. Its not doing that right now, and I'm a bit stumped. Thanks VAYKENT, for taking a look at this. Also, watch the x param in the function call.
enjoy
tutash
[Edited by tutash on 08-21-2002 at 04:57 PM]
-
Uhm...
Wow - we've hit two pages!!!
I wonder how many people we'll lose cause the page numbers are so small...
Yeah - I'll try to remember to take a look at it tonight...
-
silly rabbit
Scope the variable x inside your function:
Code:
// don't scope it here!!!
// x = 0;
// don't pass in x:
function doXML(whichXML, nodePass) {
// scope it here:
var x = 0;
...
}
-
Re: silly rabbit
Originally posted by shoehorn
Scope the variable x inside your function:
Code:
// don't scope it here!!!
// x = 0;
// don't pass in x:
function doXML(whichXML, nodePass) {
// scope it here:
var x = 0;
...
}
i really didn't need to scope x
the param(x) in the function will = 0 each time the function is called, but not while child nodes exist
Code:
function doXML(whichXML, x, nodePass) {
while (whichXML[x].hasChildNodes) {
...
//note that param(x) = 0
...
doXML(whichXML[x].childNodes, 0, string(v+"."));
x++;
}
}
// the initial node is set here.
theXML = theXML.childNodes[2].childNodes;
//note that param(x) = 0
doXML(theXML, 0, "");
this makes each recursion start from 0. the recursive function treats each node as the root of a tree. i think the script is running in preorder tranversal, but i need to trace my output for that. i think it may not be abstract enough...
here's the corrected script, sorry about that.
Code:
function doXML(whichXML, x, nodePass) {
while (whichXML[x].hasChildNodes) {
// error correction
whichXML[x].ignoreWhite = true;
if (String(whichXML[x].nodeName) == "null" ) {
whichXML[x].removeNode();
}
// the meat
v = string(nodePass+whichXML[x].nodeName+"_"+(x));
this[v] = whichXML[x].childNodes[0].nodeValue;
// recurse - note that param(x) = 0
doXML(whichXML[x].childNodes, 0, string(v+"."));
x++;
}
}
// set the root node here.
theXML = theXML.childNodes[2].childNodes;
//note that param(x) = 0
doXML(theXML, 0, "");
still trying.
enjoy
tutash
[Edited by tutash on 08-22-2002 at 11:31 AM]
-
Okay I've read this thread now a few times and am just having difficulty applying it to what I'm working on. Hope you guys can help. Here's an object I have:
Variable _level0.series1 = [object #1] {
title:"test",
date:"test",
extent:"test",
scope:"test",
subseries1:[object #2] {
title:"test",
date:"test",
extent:"test",
scope:"test",
file1:[object #3] {
title:"test",
date:"test",
extent:"test",
scope:"test",
type:"Folder"
},
file2:[object #4] {
title:"test",
date:"test",
extent:"test",
scope:"test",
type:"Folder"
}
}
}
Now I need to put it into an XML object and need to be able to have more than one series with similar children. Suggestions?
-
just bumping to see if anyone has made progress in this area.
enjoy
tutash
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|