How do I escape ampersands in XML so they are rendered as entities in HTML?

前端 未结 11 1724
野趣味
野趣味 2020-11-22 15:59

I have some XML text that I wish to render in an HTML page. This text contains an ampersand, which I want to render in its entity representation: &.

11条回答
  •  死守一世寂寞
    2020-11-22 16:47

    The & character is itself an escape character in XML so the solution is to concatenate it and a Unicode decimal equivalent for & thus ensuring that there are no XML parsing errors. That is, replace the character & with &.

提交回复
热议问题