2

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?

1 Answer 1

3

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>
Sign up to request clarification or add additional context in comments.

1 Comment

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".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.