xml 中允许使用字符 # 或 & 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11840981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:38:35  来源:igfitidea点击:

are characters # or & allowed in xml?

xmlampersand

提问by yital9

i have values with special chars that encoded to ascii in my xml. for example :

我在我的 xml 中有编码为 ascii 的特殊字符的值。例如 :

<?xml version="1.0" encoding="UTF-8"?>
<response>
    <name>&#381;irm&#363;n&#371;</name>
</response>

but when i parse value namei get only &as value. Is it allowed to use #or &in xml? or i have to use cdata necessarily?

但是当我解析价值时,name我只得到&价值。是否允许使用#&在 xml 中?或者我必须使用cdata?

回答by Ivan

The & character appears to be illegal, use (below) instead.

& 字符似乎是非法的,请改用(如下)。

&amp;

Invalid Characters in XML

XML 中的无效字符

The # character should be OK.

# 字符应该没问题。

Also this may be useful: http://xml.silmaril.ie/specials.html.

这也可能有用:http: //xml.silmaril.ie/specials.html

回答by victorsavu3

&needs to be escaped as it is used for esaping itself. All escapes start with &(&quot;, &lt;, &gt;).

&需要转义,因为它用于逃避自身。所有转义都以&( &quot;, &lt;, &gt;)开头。

&amp;is the escape for &

&amp;&的转义