如何在XML文档中包含&符号(&)?

前端之家收集整理的这篇文章主要介绍了如何在XML文档中包含&符号(&)?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我怎么能把& XML标记属性中的符号,同时保持XML有效?
<?xml version="1.0" ?> 
<a text="b&c"/>

当我使用W3School’s validator,我得到错误

EntityRef: expecting ‘;

使用字符参考来表示它:& amp; amp; amp;

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.

原文链接:https://www.f2er.com/xml/293315.html

猜你在找的XML相关文章