Javascript String encodeXML()

Description

Javascript String encodeXML()



String.prototype.encodeXML = function () {
  var chr_to_xml = {
    '&': '&',
    '"': '"',
    '<': '&lt;',
     '>': '&gt;'
  };/*from w w  w  .ja v  a2s .c om*/
  return this.replace(/([\&"<>])/g, function(str, item) {
    return chr_to_xml[item];
  });
};



PreviousNext

Related