|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, June 14, 2012 11:57 PM
Points: 257,
Visits: 595
|
|
Hi,
I am getting the following error when I try to parse XML.
declare @xml xml set @xml = '<?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)
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?
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:26 PM
Points: 2,359,
Visits: 3,292
|
|
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"
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, June 14, 2012 11:57 PM
Points: 257,
Visits: 595
|
|
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.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: 2 days ago @ 8:15 AM
Points: 386,
Visits: 901
|
|
thanks for the unicode reminder.... N'Was Scratching my head too'
|
|
|
|