I'm trying to generate a xml file using oracle. After generating the xml using dbms_xmldom, it is stored in a CLOB and later written to a table.
The problem is that the character set ('UTF-8') is not included in the header even though it is specified using setCharset() procedure.
Following is the oracle script,
declare
export_file_ CLOB ;
str_export_file_ xmldom.DOMDocument;
main_node xmldom.DOMNode;
root_node xmldom.DOMNode;
root_elmt xmldom.DOMElement;
begin
str_export_file_ := xmldom.newDOMDocument;
xmldom.setVersion(str_export_file_, '1.0');
xmldom.setCharset(str_export_file_ , 'UTF-8');
main_node := xmldom.makeNode(str_export_file_);
root_elmt := xmldom.createElement(str_export_file_,'TextTranslation');
xmldom.setAttribute( root_elmt, 'version' ,'1.0');
xmldom.setAttribute( root_elmt, 'language' ,'ja');
xmldom.setAttribute( root_elmt, 'module' ,'DEMOAND');
xmldom.setAttribute( root_elmt, 'type' ,'VC');
root_node := xmldom.appendChild(main_node, xmldom.makeNode(root_elmt));
export_file_ :=' ';
xmldom.writeToClob( str_export_file_,export_file_,'UTF-8');
dbms_output.put_line ( export_file_ );
end;
The output is ,
<?xml version="1.0"?>
<TextTranslation version="1.0" language="ja" module="DEMOAND" type="VC"/>
Nothing wrong so far. As a workaround you can use
export_file_ := REPLACE(
export_file_
,'<?xml version="1.0"?>'
,'<?xml version="1.0" encoding="UTF-8" ?>'
);