Problem reading XML data (MX)

Hi guys,

I can not display the data from an XML file. My code is like this:

function getdata() {
myXML=new XML();
myXML.onLoad=disp;
myXML.load(“xmldata.xml”);
}

function disp() {
trace(“disp”);
trace(myXML.firstChild.firstChild.nodeValue);
}

the content of “xmldata.xml” is :
<ABC>
<TRYING>sample data</TRYING>
</ABC>

getdata fn is called on click of a button. when i run the application it goes to the disp function but doesnot display the the data from XML file.
can anybody help me…
thanks in advance

:slight_smile:

Sup coolguy13,

  The key to your code  working should be adding an "ignorewhite" value to your XML object.  That's if your using Flash MX or Flash 5 with player version 5.0.41 or later.  The new code should look like this:

myXML=new XML();
myXML.ignoreWhite = true; // !!! new line !!!
myXML.onLoad=disp () ;
myXML.load(“xmldata.xml”);

 If this doesn't work you might also want to check the status of your XML object. Doing so allows you see if your XML document was parsed correctly.  Just add :    trace (myXML.status);    .  You want to get back a zero .  If you get another number here is the list of  all of the return  values for status and what they mean:
  • 0 No error; parse was completed successfully.

-2 A CDATA section was not properly terminated.

-3 The XML declaration was not properly terminated.

-4 The DOCTYPE declaration was not properly terminated.

-5 A comment was not properly terminated.

-6 An XML element was malformed.

-7 Out of memory.

-8 An attribute value was not properly terminated.

-9 A start-tag was not matched with an end-tag.

-10 An end-tag was encountered without a matching start-tag.

// List of values provided by Macromedia’s ActionScript Dictionary.

Hope it works coolguy13 !

–PabScript

tks for ur reply pabscript,

I m using FLASH MX. I tried myXML.ignoreWhite = true; also.
& checked the status: trace(myXML.status); it returns zero means there is no error in parsing but still i m unable to dispaly the value…
pls help

Thanks again

guys

please help!!!

Well, do you have “well-formed” XML? Such as…

<?xml version=“1.0” ?>
<Names>
<FirstName id=“AENIMA” />
<LastName id=“Noneofyobizness” />
</Names>

That would probably help a lot. I have also found that using attributes such as “id” for the information is idea for Flash’s ActionScript. At least this is what I have found.

myXML=new XML();
myXML.ignoreWhite = true;
myXML.onLoad=disp () ;
myXML.load(“xmldata.xml”);

function disp(success) {
if (success) {
trace(myXML);
}
}

That might work out. Who knows…just check out your XML and see if it is formed well. It’s anal like that.

Oh yea, say you want to just read the ID of one of the nodes…it would be like…

trace(myXML.firstChild.firstChild.id.nodeValue);
Ooooooooor
trace(myXML.firstChild.firstChild.id);

I can’t remember which it is, but it’s one of the two.

Of course, I’m not in the middle of testing this, but I think that’s right.

Good luck!

:cyclops: