Skip to content Skip to sidebar Skip to footer

Can I Escape HTML Entities In XML So That They Are Displayed Literally On A Web Page?

I have an XML descriptor file containing attribute specifications such as: ...

Solution 1:

Escape the ampersands in the HTML entities so you get the following:

<attribute
  name="abc"
  description="You must supply a &amp;lt;port number&amp;gt;">
...
</attribute>

The attribute value will then be seen by the Groovy script as:

You must supply a &lt;port number&gt;

Solution 2:

You can simply replace '&' to '&amp;' to work around it. Here is the code:

<div id="d"></div>
<script type='text/javascript'>
var str = "<table><tr><th>Name</th><th>Description</th></tr><tr><td>abc</td><td>You must supply a  &amp;lt;port number &amp;gt;</td></tr></table>";
document.getElementById('d').innerHTML = str;
</script>

Post a Comment for "Can I Escape HTML Entities In XML So That They Are Displayed Literally On A Web Page?"