Correction
Kevin Daines, September 27, 2016 - 8:31 pm UTC
I figured it out. Initializing the destination was not the solution I used. What's important to note is that a DBMS_XMLDOM.domnode can actually be any one of several DOM node types (revealed by DBMS_XMLDOM.getnodetype). If the node is the root node of a DBMS_XMLDOM.domdocument object, then it is considered to be a "document" node, verses an "element" node or a "notation" node (among others) if it appears lower in the document tree. Depending on the node type, you can do different things to the node. For example, you cannot add a "document" node as a child to another kind of node, which is what I was effectively trying to do. The solution was to cast the "document" node to an "element" node before cloning, as in:
src_clone := DBMS_XMLDOM.clonenode(n => DBMS_XMLDOM.makenode(DBMS_XMLDOM.getdocumentelement(src_doc)), deep => true);
September 28, 2016 - 7:35 am UTC
Nice work, and thanks for taking the time to give us an update.
Then everyone benefits.
Terrific...this really helped me!!!
Francesco Antolini, April 16, 2019 - 1:07 pm UTC
Ok, my problem was that trying to import an XMLType into a DOMDocument using dbms_xmldom.importnode(), it failed.
Using dbms_xmldom.getdocumentelement(), it worked!
1. BEFORE (didn't work)
DECLARE
...
xmlTypeElement SYS.XMLTYPE;
l_xmlDoc dbms_xmldom.domdocument;
l_testDoc dbms_xmldom.domdocument;
l_wrkNode dbms_xmldom.domnode;
l_testNode dbms_xmldom.domnode;
BEGIN
...
l_testDoc := dbms_xmldom.newDOMDocument(xmlTypeElement);
l_wrkNode := dbms_xmldom.makenode(l_testDoc);
...
l_testNode := dbms_xmldom.importnode(l_xmlDoc, l_wrkNode, TRUE);
END;
2. AFTER (IT WORKED!)
DECLARE
...
xmlTypeElement SYS.XMLTYPE;
l_xmlDoc dbms_xmldom.domdocument;
l_testDoc dbms_xmldom.domdocument;
l_wrkNode dbms_xmldom.domnode;
l_testNode dbms_xmldom.domnode;
BEGIN
...
l_testDoc := dbms_xmldom.newDOMDocument(xmlTypeElement);
l_wrkNode := dbms_xmldom.makenode(DBMS_XMLDOM.getdocumentelement(l_testDoc));
...
l_testNode := dbms_xmldom.importnode(l_xmlDoc, l_wrkNode, TRUE);
END;
April 16, 2019 - 11:49 pm UTC
Glad we could assist.