0

我有带有©符号的 xml 文件。但是 SQL 无法解析此类 XML,是否有解决方法?

这个查询:

declare @XmlResponse as xml; 
select @XmlResponse = '<?xml version="1.0" encoding="utf-8"?><Response>©</Response>'
select @XmlResponse as myxml

返回错误:

消息 9420,级别 16,状态 1,第 15
行 XML 解析:第 1 行,字符 49,非法 xml 字符

4

3 回答 3

2

您可以将©符号替换为 XML 实体&#169;

declare @XmlResponse as xml; 
select @XmlResponse = REPLACE('<?xml version="1.0" encoding="utf-8"?><Response>©</Response>', '©', '&#169;')
select @XmlResponse as myxml

有关更多 XML 实体,请参阅: http ://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

于 2013-02-15T15:37:40.083 回答
1

如果您摆脱编码,它会起作用。 是我发现的一篇关于 XML 编码的文章。我尝试使用它建议的编码,但我得到了一个不同的错误。但是,如果我完全删除编码,它就可以正常工作。

declare @XmlResponse as xml; 
select @XmlResponse = '<?xml version="1.0" ?><Response>©</Response>'
select @XmlResponse as myxml
于 2013-02-15T15:37:57.743 回答
1

问题出在encoding attribute. 如果您将其删除或将其更改utf-16. 这里有一些细节。跟随utf-16 这里的作品

declare @xml nvarchar(max) = 
'<?xml version="1.0" encoding="utf-16" ?><Response>©</Response>'
select convert(xml, @xml) myxml
于 2013-02-15T15:54:17.567 回答