I have the following function that appends a child node to a parent node and returns an XMLTYPE.
I thought DBMS_XMLDOM.appendChild was supposed to replace the old child node with the new child if it already exists, but instead it's just adding another child. Here's how I'm using it:
Produces:
Any ideas on why it's not replacing the child node, and how I might fix it?
Thanks!
Code:
FUNCTION append_element(parent XMLType, child XMLType)
RETURN XMLTYPE DETERMINISTIC IS
parent_document DBMS_XMLDOM.DOMDOCUMENT;
parent_rootnode DBMS_XMLDOM.DOMNODE;
child_document DBMS_XMLDOM.DOMDOCUMENT;
child_rootnode DBMS_XMLDOM.DOMNODE;
BEGIN
parent_document := DBMS_XMLDOM.newDOMDocument(parent);
parent_rootnode := DBMS_XMLDOM.makeNode(DBMS_XMLDOM.getDocumentElement(parent_document));
child_document := DBMS_XMLDOM.newDOMDocument(child);
child_rootnode := DBMS_XMLDOM.makeNode(DBMS_XMLDOM.getDocumentElement(child_document));
parent_rootnode := DBMS_XMLDOM.appendChild(parent_rootnode, child_rootnode);
RETURN parent;
END append_element;
I thought DBMS_XMLDOM.appendChild was supposed to replace the old child node with the new child if it already exists, but instead it's just adding another child. Here's how I'm using it:
Code:
PROCEDURE main IS
v_xml XMLTYPE := XMLTYPE('<parent></parent>');
BEGIN
v_xml := append_element(v_xml, XMLType('<child>one</child>'));
v_xml := append_element(v_xml, XMLType('<child>two</child>'));
htp.p('<textarea cols=50 rows=5>' || htf.escape_sc(v_xml.getClobVal()) || '</textarea>');
htp.br;
END main;
Produces:
Code:
<parent>
<child>one</child>
<child>two</child>
</parent>
Any ideas on why it's not replacing the child node, and how I might fix it?
Thanks!