Search code examples
sqlxmloracle-databaseplsqlxmldom

Missing encode info on XML header using XMLDOM


i want to print xml header with xmldom. The problem is, it prints only the xml version but missing the encode information.

What i got :

<?xml version="1.0"?>

What i want:

<?xml version="1.0"  encoding="UTF-8"?>

im using ORACLE 11g

And here is what i got so far:

doc     := xmldom.newdomdocument;
xmldom.setversion(doc,'1.0');        
xmldom.setCharset(doc,'UTF-8');
mainNode := xmldom.makeNode(doc);

rootElmt := xmldom.createElement(doc,'Dokument');
rootNode := xmldom.appendChild (mainNode,xmldom.makeNode(rootElmt));
SetCurNode (rootNode);

dbms_lob.createTemporary(vClob,true); 
dbms_xmldom.writeToClob (doc,vClob);
xmldom.freedocument  (doc);

Thanks in advance,

Ivan


Solution

  • Not entirely sure why charset isn't included in the output, but it seems to be a common issue. One alternative (shown here: https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:2791321000346652231) is to do the following:

    xmldom.setVersion(doc,'1.0" encoding="UTF-8');
    

    Edit: Apparently, the character set you specify is ignored unless you use the writeToFile procedure, this would explain why it is not being included in the output when using writeToClob