sql server - Converting accented characters in varchar() to XML causing "illegal XML character" -


i have table written application. field varchar(max). data looks xml.

declare @poit varchar(100) set @poit = '<?xml version="1.0" encoding="utf-8"?><test>vÍa</test>' select convert(xml,@poit) 

but (seemingly because of utf8; removing works), error:

xml parsing: line 1, character 46, illegal xml character 

is there way cleanly convert it?

i found thread, talks varchar not supporting "non-ascii characters", though non-unicode. yes, can this:

select convert(xml, replace(@poit, 'encoding="utf-8"', ''))

but best way?

why casting utf-8 varchar column xml require converting nvarchar , encoding change?

i try changing datatype of @poit variable varchar(100) nvarchar(100). replace utf-8 encoding utf-16 code like:

    declare @poit nvarchar(100)     set @poit = '<?xml version="1.0" encoding="utf-8"?><test>vÍa</test>'     select convert(xml,replace(@poit, 'utf-8', 'utf-16')) 

as long you're not calling conversion replace in in select returns oodles of results, performance should fine , job done.

reference: http://xml.silmaril.ie/characters.html <- scroll down , you'll see info difference between utf-8 & utf-16. hope helps!


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -