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>&mdash; &amp; &lt; &gt; &quot; &apos; &nbsp;</foo></doc>

trace (myXML) //                   &amp;mdash; &amp; &lt; &gt; " ' ᅠ
trace (myXML.toXMLString()) //     &amp;mdash; &amp; &lt; &gt; " ' ᅠ
trace (myXML.toString()) //        &amp;mdash; &amp; &lt; &gt; " ' ᅠ
trace ("--") //
trace ( //               &mdash; & < > " ' ᅠ
trace ( // &amp;mdash; &amp; &lt; &gt; " ' ᅠ
trace ( //    &mdash; & < > " ' ᅠ

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.

Related articles

 Comments 1 comment

  • […] I encountered in this post, ActionScript will reENcode ampersands on entities it doesn’t understand when you get XML content […]

  • Leave a Reply

    Your email address will not be published. Fields with * are mandatory.