PDA

View Full Version : BIIIG problem with XML


Weebbo2000
11-01-2001, 07:56 AM
i'm about to loose my mind with this one (and it's not backed-up on disk :))

in the first frame of the main timeline i have the following script:

testXML = new XML();
testXML.load("4test.xml");
y = testXML.firstChild.attributes.name;
trace (y);
z = testXML.firstChild.attributes.order;
trace(z);

the file 4test.xml (which is located in the same directory as the movie) contains this:

<mytag name="Val" order="first">intem</mytag>

(copied from the actionscript dictionary examples)

the problem is that nothing traces....NOTHING...NADA...ZERO...
all i get is one very empty, very white output window....


if i buid the xml locally with

srs = "<mytag name=\"Val\" order=\"first\">intem</mytag>"

and then i load it with

testXML=new XML(srs);

then everything works out fine....i've tried everything i think is humanly possible and all i got is that my flash won't load xml files.

pleaseeeeeeeeee help me out :confused: :confused: :confused:

mad_A
11-01-2001, 08:37 AM
hey there weebbo2000

There are two possible reasons why you are not getting the correct result -
1. You have whitespace (or tabs) in your XML.

To overcome this ensure you have the browser plugin version 5.0.41 or higher.
Use this code -
myXML = new XML;
myXML.ignoreWhite =true;
myXML.load("yourfile");

It will not work in the flash preview, but will work in a browser.

2. you are aiming at the wrong node.
try sticking all the child nodes into an array and trace the contents of the array. Then try each position in the array until you hit your content. (you will need to stick in content as well as attributes to get this to work).

Hope that helps.

A

Weebbo2000
11-01-2001, 08:42 AM
whew.... the most complete answer i got ever since i started using this forum...
thanx a lot :D

Weebbo2000
11-01-2001, 09:51 AM
i've tried that...the first one...it doesn't work...
i've even made a xml file that had only "asd" in it... i've tried to load it with myXML.load("asd.xml")
NOTHING!?!
and then there's the problem with the fact that i won't be using a browser....this is a standalone application delivered on a cd....
i need the xmls to update it periodically....

any other ideas?
could my flash have gotten corrupted in any way? i mean that it doesn't properly work due to an internal error it doesn't report?

mad_A
11-01-2001, 10:33 AM
You can still get it working with the standalone player if you have the xml file as a single string (no spaces, carriage returns or tabs between nodes - you can have them within nodes).

Here is some code that works. (you owe me one!!!)

x1 = new XML();
x1.ignoreWhite=true;
a1 = new Array();
x1.load("demo.xml");
function fLoadXml(){
a1 = x1.firstChild.childNodes;
name="<b>" + x1.firstChild.attributes.name + "</b>";
}
x1.onLoad = fLoadXml;

That will work if you have the this as your xml file....

<?xml version="1.0"?><mytag name="your text here">codedanswer.com</mytag>


that works perfectly. I've tried it out to see. sewt a dynamic textfield called "name" to see.

mad_A
11-01-2001, 10:33 AM
It was probably just not having the xml declaration that was throwing you.

Weebbo2000
11-01-2001, 08:45 PM
i really owe you....cause this one really worked okie....
oh,....and btw, i had the xml declaration almost all of the time, just in the last one i didn't.

thanks a world.:)