I’m posting this here mainly because I always have to look it up. But maybe this post will help someone down the road.
Converting a string with html entities (such as &) to their respective symbols:
public function htmlUnescape(str:String):String
{
return new XMLDocument(str).firstChild.nodeValue;
}
Converting a string so that it has html entities:
public function htmlEscape(str:String):String
{
return XML( new XMLNode( XMLNodeType.TEXT_NODE, str ) ).toXMLString();
}
trace(htmlEscape(“ham & eggs”)); // ham & eggs
trace(htmlUnescape(“ham & eggs”)); // ham & eggs

