ActionScript, XML, and Character Entities
Feb, 19 - 2009 1 comment Uncategorized
See if you can make heads or tails out of this behavior. I couldn’t.
var myXML:XML = <doc><foo>— & < > " ' </foo></doc>
trace (myXML) // &mdash; & < > " ' ᅠ
trace (myXML.toXMLString()) // &mdash; & < > " ' ᅠ
trace (myXML.toString()) // &mdash; & < > " ' ᅠ
trace ("--") //
trace (myXML.foo) // — & < > " ' ᅠ
trace (myXML.foo.toXMLString()) // &mdash; & < > " ' ᅠ
trace (myXML.foo.toString()) // — & < > " ' ᅠ
Why are single and double quotes (and nonbreaking spaces?!) DEcoded by toXMLString, but any entities (ampersands) Flash doesn’t handle get (re)ENcoded?
What a nightmare! I’m no encoding expert (although I did drop some cheddar on O’Reilly’s excellent “Fonts and Encodings,” a 1000+ page sleep-aid I have had zero time to actually read), but is there a rationale here I can’t see?
Still musing about what to do about it.
[…] I encountered in this post, ActionScript will reENcode ampersands on entities it doesn’t understand when you get XML content […]