Click to See Complete Forum and Search --> : XML data in, strange happenings in Flash?

06-28-2001, 10:52 AM
This is the third web app I've built that intergrates Flash and XML, but for some reason I am having problems. I made a simple test app to see if I am getting data and it doesn't work. Here is what I did.

Created xml file: "student.xml"

<?xml version="1.0"?><ESIML><student name="Alex Banks">Hello, I am a student</student></ESIML>

I ran the tags together because this is the only way I could get it to work in the past. The sturcture is really like this:

<?xml version="1.0"?>
<student name="Alex Banks">Hello, I am a student</student>

I then created a one frame test movie called student. In the first frame I typed the following ActionScript:

studentFile = new XML();

function setVars () {
var1 = studentFile.firstChild;
var2 = studentFile.firstChild.firstChild;
var3 = studentFile.firstChild.firstChild.firstChild;
var4 = studentFile.firstChild.firstChild.attributes.name. VALUE;
var5 = studentFile.firstChild.nodeName;
var6 = studentFile;

trace("var1: " + var1);
trace("var2: " + var2);
trace("var3: " + var3);
trace("var4: " + var4);
trace("var5: " + var5);
trace("var6: " + var6);

studentFile.onLoad = setVars();

When I test the movie this is the output that I get:

var1: null

What could I possibly be doing wrong. I fought with this stuff for 3 hours yesterday, and like I said I've done this before. Any weird flash rules. Something I am missing. why does it say that the xml is null? Why can't I get vars. Help please.


06-28-2001, 10:55 AM
Sorry, Here is the real XML. I replaced < with [ and > with ] so that we can see the code in the browser window.

Created xml file: "student.xml"

[?xml version="1.0"?]Hello, I am a student

I ran the tags together because this is the only way I could get it to work in the past. The sturcture is really like this:

[?xml version="1.0"?]

Hello, I am a student



06-28-2001, 07:49 PM
So if it was me... I'd take out the DTD... now that we've gotten that out of the way.... :) (FYI - Doc types give you whitespace.. yes, the dreaded whitespace that will return NULL if you want anything from it.... ;) ... )

You're using the attributes method wrong... it should be whateverNode.attributes['name'] to access the value stored inside the name attribute for the whateverNode node...

If you use the attributes method in that way (with the dot access operator) you will be trying to set a value - not retrieve one...

Personally I like using the childNodes method on XML nodes.... whateverNode.firstChild is the same as whateverNode.childNodes[0].... you won't need to use recursive functions to get to the second child in the whateverNodes list... just say whateverNode.childNodes[1] to get to the second one... childNodes[2] for the third and so on - just like an array.... actually that's what the childNodes method kinda stores..... anyway...

The point of all of this ramble is that you're probably trying to access some whitespace's firstChild's firstChild's attributes.. blah blah blah - it gets real messy at that point... ;)

Anyway... don't forget to account for any whitespace you plop in your XML docs...

Have Fun!