In JavaScript (server side nodejs) I\'m writing a program which generates xml as output.
I am building the xml by concatenating a string:
str += \'&l
If you have jQuery, here's a simple solution:
String.prototype.htmlEscape = function() { return $('').text(this.toString()).html(); };
Use it like this:
"".htmlEscape(); -> "<foo&bar>"
"".htmlEscape();
"<foo&bar>"