2013-02-15 126 views
0

我有符合©符号的xml文件。但是SQL不能解析这样的XML,对此有没有解决方法?SQL Server:从xml解析版权符号

这个查询:

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

返回一个错误:

Msg 9420, Level 16, State 1, Line 15
XML parsing: line 1, character 49, illegal xml character

回答

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

+0

感谢XML实体。 – 2013-02-15 16:00:23

+0

+1很高兴认识这个。 – Kaf 2013-02-15 16:02:17

1

它的工作原理,如果你摆脱编码。 Here是一篇关于XML编码的文章。我尝试使用它建议的编码,并且我得到了一个不同的错误。但是,如果我完全删除编码,它工作正常。

declare @XmlResponse as xml; 
select @XmlResponse = '<?xml version="1.0" ?><Response>©</Response>' 
select @XmlResponse as myxml 
+0

对不起,我不知道我的问题在哪里,忘了写我使用外部xmls,并且不能更改编码。 – 2013-02-15 16:01:48

1

问题是与encoding attribute。它会工作,如果你删除它或改变它。这里是some details。继utf-16works here

declare @xml nvarchar(max) =  
'<?xml version="1.0" encoding="utf-16" ?><Response>©</Response>' 
select convert(xml, @xml) myxml