/ Published in: ActionScript 3

These five characters should be replaced with their HTML entity names before being used in XML, otherwise they may cause the XML to be invalid.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// http://xml.silmaril.ie/authors/specials/ function replaceSpecialXmlChars($str:String):String { var regExp:RegExp; regExp = /&/g; $str = $str.replace(regExp, "&"); regExp = /</g; $str = $str.replace(regExp, "<"); regExp = />/g; $str = $str.replace(regExp, ">"); regExp = /"/g; $str = $str.replace(regExp, """); regExp = /'/g; $str = $str.replace(regExp, "'"); return $str; } var myStr:String = "<&>\"'<&>\"'"; trace(myStr); trace(replaceSpecialXmlChars(myStr)); // OUTPUT // <&>"' // <&>"'
URL: http://xml.silmaril.ie/authors/specials/
Comments
