如何在保持 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 "
&
" and "<
" respectively. The right angle bracket (>) may be represented using the string ">
", and MUST, for compatibility, be escaped using either ">
" 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/