jkelly061597
asked on
XML parsing error: Switch from current encoding to specified encoding not supported.
I am using the XML capabilities of SQL Server 8 and am running the following:
-------------------------- ---------- ---------- ---------- ---------- ---------- -
/** Begin Script for reproducing the problem **/
DECLARE @i_xml nVarChar(4000)
SELECT @i_xml = '<?xml version="1.0" encoding="utf-8" ?>
<TermRelations></TermRelat ions>'
declare @hdoc int
exec sp_xml_preparedocument @hdoc output,@i_xml
exec sp_xml_removedocument @hdoc
-------------------------- ---------- ---------- ---------- ---------- ---------- -
I get the following response from Sql Server:
Server: Msg 6603, Level 16, State 1, Procedure sp_xml_preparedocument, Line 10
XML parsing error: Switch from current encoding to specified encoding not supported.
Now,
When I change @i_xml to the following:
DECLARE @i_xml VarChar(4000)
I do not get the error... What is going on here?
I will need to support arabic languages with this sproc, hence the use of nVarChar. Can anyone provide guidance?
--------------------------
/** Begin Script for reproducing the problem **/
DECLARE @i_xml nVarChar(4000)
SELECT @i_xml = '<?xml version="1.0" encoding="utf-8" ?>
<TermRelations></TermRelat
declare @hdoc int
exec sp_xml_preparedocument @hdoc output,@i_xml
exec sp_xml_removedocument @hdoc
--------------------------
I get the following response from Sql Server:
Server: Msg 6603, Level 16, State 1, Procedure sp_xml_preparedocument, Line 10
XML parsing error: Switch from current encoding to specified encoding not supported.
Now,
When I change @i_xml to the following:
DECLARE @i_xml VarChar(4000)
I do not get the error... What is going on here?
I will need to support arabic languages with this sproc, hence the use of nVarChar. Can anyone provide guidance?
jkelly,
VARCHAR is not for unicode charset (utf-8), if you want to parse the encoding utf-8 from XML to SQL server, use NVARCHAR because NVARCHAR is for unicode. That's all
VARCHAR is not for unicode charset (utf-8), if you want to parse the encoding utf-8 from XML to SQL server, use NVARCHAR because NVARCHAR is for unicode. That's all
ASKER
That is actually the problem. When I use the nVarChar I get the error. When I use varchar I do not get the error.
Why are you specifying the enconding in the first place ? do you really need it ?
the encoding says something about how the data is supposed to be encoded, and changing from varchar to nvarchar definetely changes the encoding which is what the xml parser is complaining.
For arabic stuff just use nvarchar and do not specify any encoding.
hth
Vasco
the encoding says something about how the data is supposed to be encoded, and changing from varchar to nvarchar definetely changes the encoding which is what the xml parser is complaining.
For arabic stuff just use nvarchar and do not specify any encoding.
hth
Vasco
ASKER
The XML I am reading comes from another system, with the <xml> encoding string.
The actual SPROC uses an nText parameter to accept the xml, this demo uses the varchar/nvarchar due to availability of local variable types.
The actual SPROC uses an nText parameter to accept the xml, this demo uses the varchar/nvarchar due to availability of local variable types.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And the same applies to Text and nText.
I suspect you will have to come up with either two stored procedures or use two parameters (one text and the other ntext) and a flag to indicate encoding. You could also change the encoding from utf-8 to utf-16, prior to passing to the stored procedure.
I suspect you will have to come up with either two stored procedures or use two parameters (one text and the other ntext) and a flag to indicate encoding. You could also change the encoding from utf-8 to utf-16, prior to passing to the stored procedure.
ASKER
Thanks everyone,
I thought utf8 & 16 should both be stored in n*.
I thought utf8 & 16 should both be stored in n*.
>>I thought utf8 & 16 should both be stored in n*.<<
But then life would be too easy <g>
But then life would be too easy <g>
ASKER