将字符串转换为 XML 非法字符 [英] Convert string to XML illegal characters
本文介绍了将字符串转换为 XML 非法字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当字符串包含 &
符号时,我正在尝试将字符串转换为 XML 并遇到非法字符问题
select convert(xml,'<根><东西><test>something &这会出错</test></东西></root>')
<块引用>
XML 解析:第 3 行,第 25 个字符,非法名称字符
解决方案
您需要对 XML 中的 & 符号 &
字符进行转义.尝试将 &
替换为 &
select convert(xml,REPLACE(';<东西><test>something &这会出错</test></东西></root>','&','&'))
I'm trying to convert a string into XML and running into an illegal character issues when the string contains &
symbol
select convert(xml,
'<root>
<stuff>
<test>something & this will error</test>
</stuff>
</root>')
XML parsing: line 3, character 25, illegal name character
解决方案
You need to escape the ampersand &
character in XML. Try replacing the &
with &
select convert(xml,
REPLACE('<root>
<stuff>
<test>something & this will error</test>
</stuff>
</root>','&','&'))
这篇关于将字符串转换为 XML 非法字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文