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
are characters # or & allowed in xml?
提问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>Žirmūnų</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.
& 字符似乎是非法的,请改用(如下)。
&
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 &(", <, >).
&需要转义,因为它用于逃避自身。所有转义都以&( ", <, >)开头。
&is the escape for &
&是&的转义符

