1. XML reserved characters must be replaced with their corresponding XML entities
- ' is replaced with '
- " is replaced with "
- & is replaced with &
- < is replaced with <
- > is replaced with >
if (!String.prototype.encodeXML) {2. Use CDATA (unparsed character data)
String.prototype.encodeXML = function () {
return this.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
};
}
A CDATA section starts with "<![CDATA[" and ends with "]]>". The only downside using this method is A CDATA section cannot contain the string "]]>", so we need make sure there is no nested CDATA section in XML.
No comments:
Post a Comment