Encoding issue with openxml?

  • Hi all,

    When I run the code below, I end up with one column containing a ? and for the otherone a square. What do I have to change in order to have a € in the columns?

    Thanx.

    create table t_test (

        col_1 varchar(1)

      , col_2 nvarchar(1)

    );

    go

    create proc sp_test (@pi_text text) as begin

      declare @idoc int

      exec sp_xml_preparedocument @idoc OUTPUT,  @pi_text;

      insert into t_test

      select value, value

      from openxml (@idoc, '/root/char', 1)

      with (value nvarchar(1));

    end

    go

    exec sp_test '<?xml version="1.0" encoding="ISO-8859-1"?><root><char value="€"/></root>'

    select * from t_test

     

  • This was removed by the editor as SPAM

  • Hi,

    I have played with XML a little and I have noticed that non ASCII characters cause problems.

    I have a solution however:

    exec sp_test '<?xml version="1.0" encoding="windows-1252"?><root><char value="€"/></root>'

    This works for me!

    Although I am not sure if you have the right approach to the problem, using different charactersets in files can often have surprising results. I live in France and I lose the accents on my characters regularly. The following link shows other ways to represent the euro sign (it is also where I found the solution to your problem).

    http://www.xml.com/pub/a/2002/09/18/euroxml.html

    Cheers,

    Paul.

  • Using that encoding indeed works. However, I was hoping it could be done otherwise, since I can't really change the xml that is feeded into the application I'm building.

    Sorry I forgot to mention that rather crucial bit of info...

  • The euro symbol isn't supported in ISO-8859-1 format, so I don't think that can work like that.

    btw, notice that the example isn't disposing of the xml document with sp_xml_removedocument which would cause sql server to run out of memory if called enough.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply