如何解决 XML 中的与号 (&) 转换问题? [英] How to solve Ampersand (&) conversion issue in XML?
问题描述
我正在使用 XMLDocument 创建 XML 文件,但是当 XML 节点获取&"时作为数据,它转换为&(&)amp;"但我需要&"的实际价值,谁能告诉我如何实现它?
I am creating XML file using XMLDocument, but when XML node get '&' as data, it converting in "Ampersand(&)amp;" but i need actual value that is '&', Can anyone please tell me how can I achieve it?
结果:
推荐答案
单个 &
在 XML 文档中非法(在 CDATA 部分之外;请参阅 @rsp 的答案),所以这是不可能的.如果您的节点数据中有逐字与符号,则它必须被编码为 &
.
A single &
is illegal in an XML document (outside of CDATA sections; see @rsp's answer), so this is not possible. If there is a verbatim ampersand in your node data, it has to be encoded as &
.
但这也没有问题,因为任何 XML 阅读器在解析 XML 文件时都会将 &
解码为文字 &
.
But it's also no problem because any XML reader will decode &
as a literal &
when parsing the XML file.
这篇关于如何解决 XML 中的与号 (&) 转换问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!