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

前端 未结 11 1859
野趣味
野趣味 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 17:01

    As per §2.4 of the XML 1.0 spec, you should be able to use &.

    I tried & but this isn't allowed.

    Are you sure it isn't a different issue? XML explicitly defines this as the way to escape ampersands.

提交回复
热议问题