views:

81

answers:

1

I'm using URLLoader in an ActionScript project to read in some XML. I then process it, and put it into a textfield. Everything looks fine. However, I don't really want the XML to be external to my SWF. So I did this:

var internalXML:XML = <Content><P>It was in <City>Paris</City> that I first 
took a <Activity>walk in nature</Activity>.</P></Content>

That is, I took the identical XML and assigned it to an XML object instance directly in my ActionScript. I then run the exact same process. But this time, whitespace has been stripped out between any XML tag content and plain text.

So that the above reads in the textfield: "It was inParisthat I first took awalk in nature."

In both cases I've got XML.ignoreWhitespace = false. I also tried XML.prettyPrinting = false. No help.

Anyone have any idea what could be happening?

+1  A: 

Probably the whitespace trimming is taking place at compile time, not run time (hence the ineffectiveness of XML.IgnoreWhitespace).

To have the XML preserved verbatim until runtime (like it was when you were loading it before), just put it into a string:

var internalXML:XML = XML("<Content><P>It was in <City>Paris</City> that I first took a <Activity>walk in nature</Activity>.</P></Content>")

Cameron
Excellent suggestion, thank you Cameron. In the meantime I found a simpler solution which I imagine accomplishes the same thing. I had XML.ignoreWhitespace = false inside a handler in my main class. I moved it outside of the class and put it just after the import statements. Now it works.If the ignoreWhitespace is a static property, why would it matter where it's declared? More generally, how do you know what's done at compile time and what's done at runtime?
David
Since ignoreWhitespace is a static property, it should not matter where it is set (although sometimes there are odd bugs in Flash). Perhaps your code was not being executed when you thought it was? Also, I was only guessing about the compile-time thing. I actually have no idea what happens to inline XML (and I'm not entirely sure that it is documented). As a general rule of thumb, things that can be determined at compile-time are usually done then, since it's then done once and does not have to be done at runtime. You have to read the docs or try stuff to find out for sure.
Cameron