Converting accented characters in varchar() to XML causing “illegal XML character”

后端 未结 2 1124
迷失自我
迷失自我 2021-01-13 14:30

I have table written to by an application. The field is varchar(max). The data looks like xml.

DECLARE @poit VARCHAR(100)
SET @poit = \'

        
2条回答
  •  清酒与你
    2021-01-13 14:59

    I would try changing the datatype of your @poit variable from VARCHAR(100) to NVARCHAR(100). Then replace the utf-8 encoding with utf-16 so your code would look something like:

        DECLARE @poit NVARCHAR(100)
        SET @poit = 'VÍA'
        SELECT CONVERT(XML,REPLACE(@poit, 'utf-8', 'utf-16'))
    

    As long as you're not calling the conversion with the replace in it in a SELECT that returns oodles of results, the performance should be just fine and it will get the job done.

    Reference: http://xml.silmaril.ie/characters.html <- scroll down and you'll see some info as to the difference between utf-8 & utf-16. Hope this helps!

提交回复
热议问题