views:

156

answers:

1

I need some code for ActionScript 3.0 which will remove any characters which are not valid in an XML attribute.

Have spent some time searching google and not found what I'm after.

Can anybody help me out?

A: 
public function xmlEncodeString(str) {
  str = str.replace("<", "&lt;");
  str = str.replace(">", "&gt;");
  str = str.replace("'", "&apos;");
  str = str.replace("\"", "&quot;");
  str = str.replace("&", "&amp;");
  return str;
}
Tom
wouldn't a whitelist be a better approach?
grapefrukt