I'm trying to write an XML file encoded in UTF-8 using data from an Oracle 9 database (should also work on Oracle 11) set up with NLS_CHARACTERSET = US7ASCII, NLS_LANGUAGE = AMERICAN. I use the XMLELEMENT and xmlattributes functions in order to construct a clob, and then I create a file from this clob.
Here's a simple example:
declare
xmlval clob;
begin
SELECT XMLELEMENT( "Parent",
XMLELEMENT( "Address", xmlattributes( unistr( 'N°27' ) as "Street", unistr( '77800' ) as "PostCode", unistr( 'Paris' ) as "City" ) )
).extract('/*').getclobVal()
INTO xmlval
FROM DUAL;
dbms_xslprocessor.clob2file( xmlval, 'DIRXMLTMP', 'file.xml', nls_charset_id('AL32UTF8') );
end;
The tables in the database can contain several non-ascii characters as the client uses, I think, the Windows 1252 character code set.
Currently, I have to use the unistr function, otherwise, the procedure crashes when a field contains non-ascii characters.
Now, this code can generate the xml files but the non-ascii characters are replaced with the '?' character : 'N°27' becomes 'N?27'.
I've tried to play with the convert function in order to modify the string 'N°27' or the variable xmlval, for example :
convert( xmlval, 'WE8MSWIN1252', 'US7ASCII' )
convert( 'N°27', 'US7ASCII', 'WE8MSWIN1252' )
But I still get 'N?27' in the resulting file.
Is it possible to display these specific characters in the generated file from a us7ascii database?