Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBMS_XMLDOM.appendChild not replacing

Status
Not open for further replies.

MikeAJ

Programmer
May 22, 2002
108
US
I have the following function that appends a child node to a parent node and returns an XMLTYPE.

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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top