AJM AJM - 1 year ago 138
HTML Question

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

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:


How do I escape this ampersand in the source XML? I tried
, but this is decoded as the actual ampersand character (
), which is invalid in HTML.

So I want to escape it in such a way that it will be rendered as
in the web page that uses the XML output.

Answer Source

When your XML contains &, this will result in the text &.

When you use that in HTML, that will be rendered as &.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download