July 5, 2010 at 9:01 pm
Hi,
I am getting the following error when I try to parse XML.
declare @xml xml
set @xml =
'[Code]<?xml version="1.0" encoding="utf-16"?>
<root>
<names>
<name>test</name>
</names>
<names>
<name>test1</name>
</names>
</root>
[/Code]
'
SELECT
x.value('name[1]', 'varchar(10)') as Name
FROM
@xml.nodes('/root/names') t(x)
This XML is passed from a C# program.
This seems to work fine if i change the encoding from utf-16 to utf-8.
Why does the XM L parser fail with utf-16 as the default encoding?
July 6, 2010 at 1:33 am
Works for me. Remember UTF-16 is similar to UNICODE.
Please note the N string-prefix.
declare @xml xml
set @xml =
N'<?xml version="1.0" encoding="utf-16"?>
<root>
<names>
<name>test</name>
</names>
<names>
<name>test1</name>
</names>
</root>
'
SELECT
x.value('name[1]', 'varchar(10)') as Name
FROM
@xml.nodes('/root/names') t(x)
N 56°04'39.16"
E 12°55'05.25"
July 7, 2010 at 6:40 pm
Works for me now. Thanks a lot.
I tried parsing it as nvarchar instead of varchar, but somehow missed to spot N while passing the parameters.
March 15, 2013 at 9:01 am
thanks for the unicode reminder.... N'Was Scratching my head too'
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply