PDA

View Full Version : accessing XML data outside of function


dr.swank
10-10-2002, 08:36 PM
hi all,

ok, I am getting really frustrated here. can anyone help me figure out how to store data loaded from an xml file so I can access it outside of it's parsing function. I have added my code below. this is killing me, so please, any constructive help would be really appritiated.

var xc = new Array("1", "34", "444", "sw", "sade", "adsr");
var R;
var N1;
var F1 = "F1";
var cont = new Array(F11, F12, F13, F14, F15, F16);
function myLoad() {
trace("xml declaration: "+this.xmlDecl);
trace("xml doctype: "+this.docTypeDecl);
trace("number of articles: "+this.firstChild.childNodes.length);
trace(" ");
//root
R = this.firstChild;
//root length
RL = this.firstChild.childNodes.length;
N1 = R.childNodes[3];
F11 = N1.childNodes[0].firstChild;
F12 = N1.childNodes[1].firstChild;
F13 = N1.childNodes[2].firstChild;
F14 = N1.childNodes[3].firstChild;
F15 = N1.childNodes[4].firstChild;
F16 = N1.childNodes[5].firstChild;
//---------------------------------------------
for (n=0; n<=5; n++) {
xc[n] = (eval(F1+(n+1)));
trace(xc[n]);
}
}
//---------------------------------------------------------------
jsoXML = new XML();
jXML = new XML();
jsoXML.ignoreWhite = true;
jsoXML.onLoad = myLoad;
jsoXML.load("jsoXML.xml");


thanx in advance all.
the doctor

dr.swank
10-11-2002, 08:43 AM
so as I continue to work on this problem, here is the code development to date:


var R;
var N;
var xc = new Array();
var cont = new Array();
var ncount = new Array();
//====================================//
function myLoad() {
trace("xml declaration: "+this.xmlDecl);
trace("xml doctype: "+this.docTypeDecl);
trace("number of articles: "+this.firstChild.childNodes.length);
trace(" ");
//root of xml file
R = this.firstChild;
//root length of xml file
RL = this.firstChild.childNodes.length;
// first node with data i need
N = R.childNodes[3];
//reference to the first block as a counting unit.
U = RL-3;
UU = Math.abs(U-RL);
//xml parser to arrays ncount is main nodes, cont is content
for (m=UU; m<RL; m++) {
ncount = R.childNodes[m];
for (n=0; n<=5; n++) {
cont[n] = ncount.childNodes[n].firstChild.nodeValue;
trace(cont[n]);
}
}
}
//-----------------------------------------------//
jsoXML = new XML();
jXML = new XML();
jsoXML.ignoreWhite = true;
jsoXML.onLoad = myLoad;
jsoXML.load("jsoXML.xml");
trace("xc="+_root.xc[1]);
trace("cont= "+cont[1]);


the doctor

hangalot
10-14-2002, 02:56 AM
if your onLoad function has fired then u'r most prob not navigating the tree correctly... -- i find your code a bit weird though, some examples -->


// u innitialize an array
var ncount = new Array(); // notice it is an EMPTY array

// then a bit later u go
cont[n] = ncount.childNodes[n].firstChild.nodeValue;

// 2 populate an array use the .push(value) method
// i doubt flash has any clue what u r trying 2 do... remember NO index
//(not even zero) exist's --> the obj might be innitialized but not the actual index pointer...


i hope this helps

a tip though ... don't approach any scripting language in a lax manner since it will be hell 2 find the errors, strongly typed, and variables declared (and innitialized[when possible])!!!!!

dr.swank
10-14-2002, 06:31 AM
hey hangalot,

thanx for the reply. about this array inistializer and push method. I have been trying around with both and must be misiing something.

would:
var ncount = new Array(6);

work to make the array at least have a number of nodes?

onto the push thing, if you could be so kind, where to I have to put the push call?

cont[n].push(ncount.childNodes[n[.firstChild.nodeValue ???

I scrub the code as I figure out what works and what does not. So, just to prove it, when I finally figure the whole schebang out I will post my lovely, neat and well commented code. This is my first try at xml though...:confused:

Thanx again for the help.
the doctor

hangalot
10-14-2002, 12:31 PM
cont[n].push(ncount.childNodes[n].firstChild.nodeValue);

is wrong. notice that u r trying 2 push on an index in the array...

the array is an object and the push method adds an index 2 the array



myArray.push(whateverIwantToPush);



check out some of the tuts...

;)

dr.swank
10-14-2002, 12:49 PM
ahh, i think i get it. thanx..

so it would be:
cont.push(ncount.childNodes[n].firstChild.nodeValue)

i think my brain is a bit fried as i am learning everything parallel.. i have tried some of the tuts, actually, i am a tut junkie, but there is a limit to what i can retain in my short term memory. thanx again for the help.

the doctor