0

I am trying to create an xml file from an oracle database.

I am not able to get the correct format and was wondering if I could get some assistance.

This is part of the script:

l_record_element := dbms_xmldom.createElement(l_domdoc, 'record_type');
dbms_xmldom.setAttribute(l_record_element,'desc', r_dept.public1);
l_record_node := dbms_xmldom.appendChild(l_dept_node,dbms_xmldom.makeNode(l_record_element));

my output:

<record_type desc="Public"/>

The output I need:

<record_type desc="Public">PUBLIC</record_type>

Thanks!

0

1 Answer 1

1

You need to create and append a text node with the PUBIC value.

Demo showing that coming from the same cursor that provides the record type:

set serveroutput on

declare
  l_domdoc dbms_xmldom.domdocument;
  l_dept_node dbms_xmldom.domnode;
  l_record_node dbms_xmldom.domnode;
  l_record_element dbms_xmldom.domelement;
  l_record_text dbms_xmldom.domtext;
  l_tmp_node dbms_xmldom.domnode;
  l_xmltype xmltype;
  l_buffer varchar2(32767);
begin
  l_domdoc := dbms_xmldom.newDOMDocument; --(xmltype('<data />'));

  for r_dept in (select 'Public' as public1, 'PUBLIC' as public2 from dual) loop
    l_dept_node := dbms_xmldom.makeNode(l_domdoc);

    -- code you showed
    l_record_element := dbms_xmldom.createElement(l_domdoc, 'record_type');
    dbms_xmldom.setAttribute(l_record_element,'desc', r_dept.public1);
    l_record_node := dbms_xmldom.appendChild(l_dept_node, dbms_xmldom.makeNode(l_record_element));
    -- add a text node
    l_record_text := dbms_xmldom.createTextNode(l_domdoc, r_dept.public2);
    l_tmp_node := dbms_xmldom.appendChild(l_record_node, dbms_xmldom.makeNode(l_record_text));

    -- display the node for demo
    l_xmltype := dbms_xmldom.getXmlType(l_domdoc);
    dbms_xmldom.freeDocument(l_domdoc);
    dbms_output.put_line(l_xmltype.getClobVal);
  end loop;
end;
/

<record_type desc="Public">PUBLIC</record_type>

PL/SQL procedure successfully completed.
Sign up to request clarification or add additional context in comments.

Comments

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.