2013-02-15 49 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