西藏巴青项目

escapeForXML.js 358B

12345678910111213141516171819
  1. var XML_CHARACTER_MAP = {
  2. '&': '&',
  3. '"': '"',
  4. "'": ''',
  5. '<': '&lt;',
  6. '>': '&gt;'
  7. };
  8. function escapeForXML(string) {
  9. return string && string.replace
  10. ? string.replace(/([&"<>'])/g, function(str, item) {
  11. return XML_CHARACTER_MAP[item];
  12. })
  13. : string;
  14. }
  15. module.exports = escapeForXML;