are characters # or & allowed in xml?

不想你离开。 提交于 2019-11-26 17:14:40

问题


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

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

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


回答1:


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

&amp;

Invalid Characters in XML

The # character should be OK.

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




回答2:


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

&amp; is the escape for &



来源:https://stackoverflow.com/questions/11840981/are-characters-or-allowed-in-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!