Flash XML object problem

  • clicky
  • Student
  • Student
  • clicky
  • Posts: 74
  • Loc: USA

Post 3+ Months Ago

During an attempt to access an XML node (flash for element), I have no success. However, toString() is referenced correctly.

Code: [ Select ]
rootNode = new XML();
rootNode.onLoad = function (success) { trace("Load successful");}

rootNode.onLoad = function (success) {
if (success) {
  msg="this.status: " + this.status + "\n";
    msg+="this.toString(): " + "\n" + this.toString() + "\n";
    msg +="this.firstChild.nodeName: " + this.firstChild.nodeName;
  } else {
   msg+="Loading error";
  }
}
rootNode.load ("xmldoc.xml");
  1. rootNode = new XML();
  2. rootNode.onLoad = function (success) { trace("Load successful");}
  3. rootNode.onLoad = function (success) {
  4. if (success) {
  5.   msg="this.status: " + this.status + "\n";
  6.     msg+="this.toString(): " + "\n" + this.toString() + "\n";
  7.     msg +="this.firstChild.nodeName: " + this.firstChild.nodeName;
  8.   } else {
  9.    msg+="Loading error";
  10.   }
  11. }
  12. rootNode.load ("xmldoc.xml");


output:
Quote:
this.status:0
this.toString():
<?xml version="1.0" encoding="ISO-8859-1"?>

<website>
<home>
Welcome
</home>
</website>


this.firstChild.nodeName: null


IMO, the only reason why toString() would work and access to a node would not, would be because the XML document is not syntactically correct. However, as can be seen by toString(), the XML is fine. I thought the DTD might be getting recognized as a node, but deleting it did not produce a different effect.
Furthermore, "this.firstChild.firstChild.nodeName" produces "undefined"
I am not sure where this is going wrong, but any help is appreciated.

P.S. The result, '0', of "this.status" indicates that there were no loading errors.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Abelius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 260
  • Loc: Miami Beach, FL, USA

Post 3+ Months Ago

Try this. It shows only the word "website" as a result in a dynamic textfield, which is the actual content of the node.

Code: [ Select ]
rootNode = new XML();
rootNode.onLoad = function(success) {
    trace("Load successful");
};
rootNode.onLoad = function(success) {
    if (success) {
        //_root.msg.text = "this.status: " + this.status + "\n";
        //_root.msg.text += "this.toString(): " + "\n" + this.toString() + "\n";
        _root.msg.text += this.firstChild.nextSibling.nodeName;
    } else {
        _root.msg.text += "Loading error";
    }
};
rootNode.load("xmldoc.xml");
  1. rootNode = new XML();
  2. rootNode.onLoad = function(success) {
  3.     trace("Load successful");
  4. };
  5. rootNode.onLoad = function(success) {
  6.     if (success) {
  7.         //_root.msg.text = "this.status: " + this.status + "\n";
  8.         //_root.msg.text += "this.toString(): " + "\n" + this.toString() + "\n";
  9.         _root.msg.text += this.firstChild.nextSibling.nodeName;
  10.     } else {
  11.         _root.msg.text += "Loading error";
  12.     }
  13. };
  14. rootNode.load("xmldoc.xml");


Two differences tho:
1) I took out the variable "msg" and gave it the INSTANCE name "msg", so in the code I replaced "msg=" by "_root.msg.text="
2) If you take out the comment of the two first lines, you keep getting the UN-desired result, just like before...

Let me know if it's what you were looking for... :)
  • clicky
  • Student
  • Student
  • clicky
  • Posts: 74
  • Loc: USA

Post 3+ Months Ago

Thanks for the reply.
It turned out most of the errors came from the lack of elimination of white space (which the flash parser does not allow).
However, you are right about me forgetting to reference the instance name before the text field's variable name.

Thanks again,
-clicky
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

clicky wrote:
Thanks for the reply.
It turned out most of the errors came from the lack of elimination of white space (which the flash parser does not allow).

Code: [ Select ]
myXML = new XML();
myXML.ignoreWhite = true;
  1. myXML = new XML();
  2. myXML.ignoreWhite = true;


That doesn't work for eliminating whitespace for you ?
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

You know what cracks me up. ignoreWhite is pretty much a required property to have set to true whenever handling XML loading. I cannot honestly think of any time when you would not want to ignore whitespace when loading XML into Flash, especially considering the way Flash parses the XML... if you don't ignore the whitespace, you cannot properly parse/read your data.

So with that said... why doesn't Macromedia just automatically include this in the process of loading in an XML file?!

And if... by some very odd chance... someone actually needs to have ignoreWhite set to false, they could just have like an optional argument to the XML.load() command. Something like...

XML.load('file.xml'[, ignoreWhite]);

Where if the ignoreWhite argument is not defined, it is automatically set to true.

Sorry, this just always annoyed me about XML in Flash... it's just one line, but it ALWAYS has to be there, and I don't see a need for it to have to be. It would be like always having to define a colour to your TextFormat object instead of it just being default black if no colour was defined.

</rant>

Sorry about that.
  • clicky
  • Student
  • Student
  • clicky
  • Posts: 74
  • Loc: USA

Post 3+ Months Ago

-lostinbeta: Agreed.

-joebert: Yes, that code works and is what I ended up using. I was merely explaining what had been wrong before, sorry for any misunderstanding.

Very respectfully,
-clicky

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 10 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.