Skip to Content
Sep 15 at 10:03 AM

Exporting UTF non-English chars in XML file with UNLOAD


Hi, SQL Anywhere

We have a database with CHAR encoding set Western Latin 1252, and NCHAR encoding set UTF-8 which is giving us a problem when we are exporting some NVARCHAR non-English characters. We are doing this by using UNLOAD SELECT XMLGEN call on a SELECT query to save the results of the query in XML format.

We get the error message

Control character in XML output
SQLCODE=-911, ODBC 3 State = "HY000"

Our procedure calls a statement

EXECUTE IMMEDIATE 'UNLOAD SELECT XMLGEN( ''<?xml version="1.0" encoding="UTF-8" ?><Root>{$x}</Root>'',
SELECT field1, field2 etc etc...
for xml auto, elements) AS x ) TO ' + filepath_filename + ' ENCODING ''UTF-8'' format ASCII quotes off escapes off';

and if any of the fields we are selecting gets a non-English character, we get the above message.

Curiously, when I try it on the copy of the database which has both CHAR and NCHAR encoding sets of UTF-8, then no problems at all - XML file is output and saved with all sorts of non-English characters without any problems.

But I'd prefer to keep CHAR encoding set of Latin1252 / NCHAR of UTF-8 if possible, so I'd like to see if I can resolve the above problem?