xml - 如何在 XML 文档中包含与号 (&) 字符?

标签 xml validation

如何在保持 XML 有效的情况下将 & 符号放入 XML 标记的属性中?

<?xml version="1.0" ?> 
<a text="b&c"/>

当我使用 W3School's validator 时,我得到错误:

EntityRef: expecting ';'

最佳答案

用字符引用来表示:&

参见 specification :

The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings " &amp; " and " &lt; " respectively. The right angle bracket (>) may be represented using the string " &gt; ", and MUST, for compatibility, be escaped using either " &gt; " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.

关于xml - 如何在 XML 文档中包含与号 (&) 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14500800/

相关文章:

android - 海拔不适用于 LinearLayout

java - 背景图像似乎没有填满整个屏幕

javascript - AngularJS 指令未按预期更新 View

php - ZF2 从验证器链中移除验证器

Jquery.Validate 基于条件

javascript - 在 initComponent 中验证

Android:DP中的启动器图标宽度和高度

java - 如何在 jaxb marshaller 中添加 DOCTYPE

html - 为什么 XPath contains(text() ,'substring' ) 没有按预期工作?

javascript - 需要一个允许所有特殊字符的密码验证正则表达式