0

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

<attribute
  name="abc"
  description="xyz e.g. &lt;br&gt; with a new line">
...
</attribute>

These XML descriptors are parsed by a groovy script to produce HTML documentation (among other things) along the lines of:

<table>
  <tr><th>Name</th><th>Description</th></tr>
  <tr><td>abc</td><td>xyz e.g. <br>with a new line</td></tr>
</table>

My question is what do I have to put in the XML to display HTML entities as character literals? e.g. A less than sign, such as:

<table>
  <tr><th>Name</th><th>Description</th></tr>
  <tr><td>abc</td><td>You must supply a &lt;port number&gt;</td></tr>
</table>

(The groovy script does no processing on the XML description - just prints it into the HTML file.)

3
  • Something tells me that those name and description attributes will be better as child elements of <attribute> instead. Of course, unless its schema is out of your control... Commented Sep 23, 2011 at 4:59
  • The schema is not directly under my control. Would that help with the problem? Commented Sep 23, 2011 at 5:03
  • It doesn't complicate things much, fortunately. That was simply a passing remark :) Commented Sep 23, 2011 at 5:05

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.