jeudi 21 mai 2015

XML string to xml unable to switch encoding

I have an XML string that is malformed.

DECLARE @xmlt TABLE(xstr nvarchar(max), xml xml)

INSERT INTO @xmlt(xstr) VALUES (
'  <?xml version="1.0" encoding="windows-1257" ?>
- <objects><object id="778913">a</object>
- <object id="785491">b</object>
- <object ...goes on...
- </objects>
'

To be able to use that XML I convert it to XML

UPDATE @xmlt SET xml = CAST(REPLACE(LTRIM(xstr), ' - <', '<') AS xml);

But I get an error XML parsing: line 1, character 46, unable to switch the encoding.

Is there any other way (without replacing the string encoding="windows-1257" with "") to convert that XML string to xml in SQL Server?

Aucun commentaire:

Enregistrer un commentaire