how to escape xml entities in javascript?

前端 未结 10 1179
醉话见心
醉话见心 2020-11-27 14:51

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         


        
10条回答
  •  北海茫月
    2020-11-27 15:39

    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>"

提交回复
热议问题