views:

358

answers:

1

I am trying to put together an XML document from several pieces. To get the data, I had several queries whose results were XMLTypes.

I found a function named getNodeFromFragment in the xmldom package that looked like it could take these XMLTypes and return a DOMNode that contained them, but it doesn't seem to work.

Simple example here:

set serveroutput on;
declare
    node xmldom.DOMNode;
    node2 xmldom.DOMNode;
    doc_node xmldom.DOMNode;
    doc xmldom.DOMDocument;
    el xmldom.DOMElement;
    buf varchar2(1000);
begin
    doc := xmldom.newDOMDocument;

    el := xmldom.createElement(doc => doc, tagName => 'test');
    node := xmldom.makeNode(elem => el);

    xmldom.writeToBuffer(node, buf);
    dbms_output.put_line('buffer: '||buf);

    node := dbms_xmldom.getNodeFromFragment(XMLType('<outer><inner>soemthing</inner><inner>somethingelse</inner></outer>'));

    xmldom.writeToBuffer(node, buf);
    dbms_output.put_line('buffer: '||buf);
end;

/

Printing the <test/> element works fine, but when I try to print the fragment as a node, nothing is output.

Any tips on getNodeFromFragment?

+2  A: 

Hi FrustratedWithFormsDesigner,

the following will create a DOMnode object from an XMLType:

node := dbms_xmldom.makenode(dbms_xmldom.newDOMDocument(XMLType(
     '<outer><inner>soemthing</inner><inner>somethingelse</inner></outer>')));

This will output:

buffer: <outer>
  <inner>soemthing</inner>
  <inner>somethingelse</inner>
</outer>
Vincent Malgrat
Yay! That works! Though now I have to merge that document with an existing document. Trying gives me "DOM nodes do not belong to the same DOM document".
FrustratedWithFormsDesigner