如何在保持XML有效的同時將&
符號放入XML標記的屬性中?如何在XML文檔中包含&符號(&)?
<?xml version="1.0" ?>
<a text="b&c"/>
當我使用W3School's validator,我得到的錯誤:
EntityRef: expecting '
;
'
如何在保持XML有效的同時將&
符號放入XML標記的屬性中?如何在XML文檔中包含&符號(&)?
<?xml version="1.0" ?>
<a text="b&c"/>
當我使用W3School's validator,我得到的錯誤:
EntityRef: expecting '
;
'
使用字符引用來表示它:&
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.
我喜歡這個回答比其他問題的答案要好,因爲它引用了規範和我能夠逃脫所有潛在的字符,而不是OP的一個字符 – RozzA