how to escape xml entities in javascript?

前端 未结 10 1192
醉话见心
醉话见心 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:29

    Technically, &, < and > aren't valid XML entity name characters. If you can't trust the key variable, you should filter them out.

    If you want them escaped as HTML entities, you could use something like http://www.strictly-software.com/htmlencode .

提交回复
热议问题