我可以使用XML转义HTML实体吗?这样它们就可以在网页上直接显示了吗? [英] Can I escape HTML entities in XML so that they are displayed literally on a web page?

查看:156
本文介绍了我可以使用XML转义HTML实体吗?这样它们就可以在网页上直接显示了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML描述符文件,其中包含以下属性规范:

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>

这些XML描述符被groovy脚本解析,以产生HTML文档(除其他外)

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>

我的问题是我必须在XML中将HTML实体显示为字符文字?例如小于号,例如:

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>

(groovy脚本没有对XML描述进行处理 - 只是将它打印到HTML文件中。)

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

推荐答案

在HTML实体中跳过&符号,以获得以下内容:

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>

Groovy脚本将会看到该属性值:

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

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

这篇关于我可以使用XML转义HTML实体吗?这样它们就可以在网页上直接显示了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆