Dbms_xmldom

Hello there,
I'm new to XML and have been asked to produce an XML file from a table. I've viewed various sites and it appears the recommendation is to use "dbms_xmldom".
I have attached the DTD (my_dtd.txt) and an example of the required XML file (sample.xml).  I've also attached the PLSQL I'm using to extract the data and the result is below. I can't figure out how to prevent <impc_location_code> element from repeating or the place the elemnt <received_receptacle> in the output.
Any assistance is greatly appreciated.
Kind regards,
Paul
DECLARE
   l_xmltype XMLTYPE;
   l_domdoc dbms_xmldom.DOMDocument;
   l_root_node dbms_xmldom.DOMNode;
   l_rec_at_loc_element dbms_xmldom.DOMElement;
   l_rec_at_loc_node dbms_xmldom.DOMNode;
   l_rec_element dbms_xmldom.DOMElement;
   l_rec_node dbms_xmldom.DOMNode;
   l_loc_element dbms_xmldom.DOMElement;
   l_loc_node dbms_xmldom.DOMNode;
   l_loc_text dbms_xmldom.DOMText;
   l_loc_textnode dbms_xmldom.DOMNode;
   l_workstation_element dbms_xmldom.DOMElement;
   l_workstation_node dbms_xmldom.DOMNode;
   l_workstation_text dbms_xmldom.DOMText;
   l_workstation_textnode dbms_xmldom.DOMNode;
   l_amu_timestamp_element dbms_xmldom.DOMElement;
   l_amu_timestamp_node dbms_xmldom.DOMNode;
   l_amu_timestamp_text dbms_xmldom.DOMText;
   l_amu_timestamp_textnode dbms_xmldom.DOMNode;
BEGIN
   -- Create an empty XML document
   l_domdoc := dbms_xmldom.newDomDocument;
   -- Create a root node
   l_root_node := dbms_xmldom.makeNode(l_domdoc);
   -- Create a new node Rec_at_loc and add it to the root node
   l_rec_at_loc_element := dbms_xmldom.createElement(l_domdoc, 'received_receptacle_at_loc' );
   l_rec_at_loc_node := dbms_xmldom.appendChild(l_root_node,dbms_xmldom.makeNode(l_rec_at_loc_element));
   FOR r_rec IN (SELECT  impc_location_code
                       , receptacle_scan
                       , workstation
                       , to_char(amu_timestamp,'YYYY-MM-DD HH24:MI:SS') amu_timestamp
                    FROM my_table
   LOOP
      l_loc_element := dbms_xmldom.createElement(l_domdoc, 'impc_location_code ' );
      l_loc_node := dbms_xmldom.appendChild(l_rec_at_loc_node,dbms_xmldom.makeNode(l_loc_element));
      l_loc_text := dbms_xmldom.createTextNode(l_domdoc, r_rec.impc_location_code );
      l_loc_textnode := dbms_xmldom.appendChild(l_loc_node,dbms_xmldom.makeNode(l_loc_text));
      l_rec_element := dbms_xmldom.createElement(l_domdoc, 'receptacle_scan ' );
      dbms_xmldom.setAttribute(l_rec_element, 'cd', r_rec.receptacle_scan);
      l_rec_node := dbms_xmldom.appendChild(l_rec_at_loc_node,dbms_xmldom.makeNode(l_rec_element));
      l_workstation_element := dbms_xmldom.createElement(l_domdoc, 'workstation-id' );
      l_workstation_node := dbms_xmldom.appendChild(l_rec_node,dbms_xmldom.makeNode(l_workstation_element));
      l_workstation_text := dbms_xmldom.createTextNode(l_domdoc, r_rec.workstation );
      l_workstation_textnode := dbms_xmldom.appendChild(l_workstation_node,dbms_xmldom.makeNode(l_workstation_text));
      l_amu_timestamp_element := dbms_xmldom.createElement(l_domdoc, 'amu_timestamp' );
      l_amu_timestamp_node := dbms_xmldom.appendChild(l_rec_node,dbms_xmldom.makeNode(l_amu_timestamp_element));
      l_amu_timestamp_text := dbms_xmldom.createTextNode(l_domdoc, r_rec.amu_timestamp);
      l_amu_timestamp_textnode := dbms_xmldom.appendChild(l_amu_timestamp_node,dbms_xmldom.makeNode(l_amu_timestamp_text));
   END LOOP;
   l_xmltype := dbms_xmldom.getXmlType(l_domdoc);
   dbms_xmldom.freeDocument(l_domdoc);
   dbms_output.put_line(l_xmltype.getClobVal);
END;
MY RESULT
<received_receptacle_at_loc>
  <impc_location_code >SITE1</impc_location_code >
  <receptacle_scan  cd="123456789A">
    <workstation-id>976400194727994800</workstation-id>
    <amu_timestamp>2013-11-07 14:08:18</amu_timestamp>
  </receptacle_scan >
  <impc_location_code >SITE1</impc_location_code >
  <receptacle_scan  cd="123456789B">
    <workstation-id>976400194727994800</workstation-id>
    <amu_timestamp>2013-11-07 14:08:41</amu_timestamp>
  </receptacle_scan >
  <impc_location_code >SITE1</impc_location_code >
  <receptacle_scan  cd="123456789C">
    <workstation-id>976400194727994800</workstation-id>
    <amu_timestamp>2013-11-07 14:09:45</amu_timestamp>
  </receptacle_scan >
</received_receptacle_at_loc>

Hi Paul,
I've viewed various sites and it appears the recommendation is to use "dbms_xmldom".
Not really... or maybe it was, 15 years ago
The easiest way is to use SQL/XML functions :
select xmlserialize(document
         xmlelement("received_receptacle_at_loc"
         , xmlagg(
             xmlelement("received_receptacle"
             , xmlelement("impc_location_code", t.impc_location_code)
             , xmlagg(
                 xmlelement("receptacle_scan"
                 , xmlattributes(t.receptacle_scan as "cd")
                 , xmlelement("workstation-id", t.workstation)
                 , xmlelement("amu_timestamp", to_char(t.amu_timestamp,'YYYY-MM-DD HH24:MI:SS'))
                 order by t.receptacle_scan -- if needed
             order by t.impc_location_code -- if needed
         as clob
         indent -- for debugging purpose
from my_table t
group by t.impc_location_code ;
This will give you a CLOB on which you can further add the XML prolog and the DTD reference.

Similar Messages

  • Oracle dbms_xmldom.ISNULL what's the difference in 10G and 11G?

    For the code below, in Oracle 10g, it says the node is empty, in 11g, it's not empty. There is a newline character in side the tag .
    If there is a space inside, the result is the same for both version.
    Once nothing inside, both two version will not have the output.
    Why does this happen ?
    DECLARE
    v_doc dbms_xmldom.DOMDocument;
    v_elem dbms_xmldom.DOMElement;
    v_nelem dbms_xmldom.DOMNode;
    BEGIN
    -- create the DOMDocument
    v_doc := dbms_xmldom.newDOMDocument(xmlType('<XMLDATA>
    </XMLDATA>'));
    v_nelem := DBMS_XMLDOM.MAKENODE(v_doc);
    v_nelem := DBMS_XSLPROCESSOR.SELECTSINGLENODE(v_nelem,'XMLDATA/text()');
    IF NOT(dbms_xmldom.ISNULL(v_nelem)) THEN
    DBMS_OUTPUT.PUT_LINE('The node is not empty');
    END IF;
    END;
    Edited by: 972302 on Nov 20, 2012 10:35 AM

    Post exact version numbers. I can't reproduce it:
    SQL> select  *
      2    from  v$version
      3  /
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    PL/SQL Release 10.2.0.5.0 - Production
    CORE    10.2.0.5.0      Production
    TNS for 64-bit Windows: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
    SQL> DECLARE
      2  v_doc dbms_xmldom.DOMDocument;
      3  v_elem dbms_xmldom.DOMElement;
      4  v_nelem dbms_xmldom.DOMNode;
      5  BEGIN
      6  -- create the DOMDocument
      7  v_doc := dbms_xmldom.newDOMDocument(xmlType('<XMLDATA>
      8  </XMLDATA>'));
      9  v_nelem := DBMS_XMLDOM.MAKENODE(v_doc);
    10  v_nelem := DBMS_XSLPROCESSOR.SELECTSINGLENODE(v_nelem,'XMLDATA/text()');
    11  IF NOT(dbms_xmldom.ISNULL(v_nelem)) THEN
    12  DBMS_OUTPUT.PUT_LINE('The node is not empty');
    13  END IF;
    14  END;
    15  /
    The node is not empty
    PL/SQL procedure successfully completed.
    SQL> 
    SQL> select  *
      2    from  v$version
      3  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    SQL> DECLARE
      2  v_doc dbms_xmldom.DOMDocument;
      3  v_elem dbms_xmldom.DOMElement;
      4  v_nelem dbms_xmldom.DOMNode;
      5  BEGIN
      6  -- create the DOMDocument
      7  v_doc := dbms_xmldom.newDOMDocument(xmlType('<XMLDATA>
      8  </XMLDATA>'));
      9  v_nelem := DBMS_XMLDOM.MAKENODE(v_doc);
    10  v_nelem := DBMS_XSLPROCESSOR.SELECTSINGLENODE(v_nelem,'XMLDATA/text()');
    11  IF NOT(dbms_xmldom.ISNULL(v_nelem)) THEN
    12  DBMS_OUTPUT.PUT_LINE('The node is not empty');
    13  END IF;
    14  END;
    15  /
    The node is not empty
    PL/SQL procedure successfully completed.
    SQL> SY.

  • How to handle dbms_xmldom with no data values.(no_data_found error in dom)

    hi,
    i have below block,
    DECLARE
    doc dbms_xmldom.DOMDocument;
    node dbms_xmldom.DOMNode;
    elem dbms_xmldom.DOMElement;
    cur_node dbms_xmldom.DOMNode;
    root_elem_data dbms_xmldom.DOMElement;
    root_elem_tab dbms_xmldom.DOMElement;
    root_node_data dbms_xmldom.DOMNode;
    mode_elmn dbms_xmldom.DOMElement;
    mode_node dbms_xmldom.DOMNode;
    mode_text dbms_xmldom.DOMText;
    doc1 DBMS_XMLDOM.DOMDOCUMENT;
    root_node_data1 DBMS_XMLDOM.DOMNODE;
    child_document DBMS_XMLDOM.DOMDOCUMENT;
    child_rootnode DBMS_XMLDOM.DOMNODE;
    V_CLOB CLOB;
    v_doc CLOB;
    v_EMP CLOB;
    v_output_filename VARCHAR2(300) := 'SPOOL_DIR/'||'EMP_XML_FILE.xml';
    l_xmltype XMLTYPE;
    BEGIN
    doc := dbms_xmldom.newDOMDocument;
    node := dbms_xmldom.makeNode(doc);
    dbms_xmldom.setversion(doc, '1.0');
    dbms_xmldom.setCharset(doc, 'UTF8');
    elem := dbms_xmldom.createElement(doc, 'PartnerInfo');
    dbms_xmldom.setAttribute(elem,'xmlns','EMP');
    cur_node := dbms_xmldom.appendChild(node, dbms_xmldom.makeNode(elem));
    mode_elmn := dbms_xmldom.createElement(doc, 'EMPLOYEE');
    mode_node := dbms_xmldom.appendChild(cur_node,dbms_xmldom.makeNode(mode_elmn));
    BEGIN
    SELECT value(e) INTO l_xmltype
    FROM TABLE(XMLSequence(Cursor(SELECT * FROM EMP1 where EMPNO=7501))) e;
    child_document := DBMS_XMLDOM.newDOMDocument(l_xmltype);
    root_node_data1 := dbms_xmldom.importNode(doc,dbms_xmldom.makeNode(dbms_xmldom.getDocumentElement(child_document)),TRUE);
    root_node_data1 := DBMS_XMLDOM.appendChild(root_node_data, root_node_data1);
    EXCEPTION
    WHEN OTHERS THEN
    Dbms_Output.Put_Line('Error in SELECT stmt(UC_PARTNER_MS):::'||'error::'||SQLERRM);
    END;
    dbms_lob.createtemporary(v_doc, true);
    dbms_xmldom.writeToClob(doc,v_doc,'UTF8');
    v_EMP:= v_doc;
    dbms_xmldom.writeToFile(DOC,v_output_filename,'UTF8');
    dbms_xmldom.freeDocument(doc);
    --Dbms_Output.Put_Line('THE OUTPUT IS::'||V_EMP);
    EXCEPTION
    WHEN OTHERS THEN
    Dbms_Output.Put_Line('Error in SELECT stmt(UC_PARTNER_MS):::'||'error::'||SQLERRM);
    END;
    The xml file is 'EMP_XML_FILE.xml'
    <empno>U++kYmcVuGchxbh+++++++++++++++1+</empno>
    <empname>J</empname>
    suppose the empno 7501 is not available in our emp table,
    i got error
    ORA-03113: end-of-file on communication channel
    how to handle xmldom with no data values.
    by
    siva

    hi,
    please give the solution
    by
    siva

  • Error when using DBMS_XMLDOM package

    Hello,
    I have created a set of triggers that use the DBMS_XMLDOM packages. These triggers were created on a Win 2k install of 9.2.0.2.1. A brand new user was created and a specific set of permissions granted. The permissions were:
    GRANT CONNECT, RESOURCE, AQ_ADMINISTRATOR_ROLE, AQ_USER_ROLE
    GRANT EXECUTE ON DBMS_AQADM
    GRANT EXECUTE ON DBMS_AQ
    grant execute on dbms_aqin
    execute dbms_java.grant_permission('<USER>', 'java.net.SocketPermission', 'localhost:1024-', 'accept, listen, resolve');
    execute dbms_java.grant_permission( '<USER>', 'SYS:java.lang.RuntimePermission', ' getClassLoader', '' )
    execute dbms_java.grant_permission( '<USER>', 'SYS:java.lang.RuntimePermission' , 'setContextClassLoader', '' )
    I then went to install these triggers on our application database server. This is a Solaris installation that started out as 9.2.0.1.0 and was then upgraded to 9.2.0.2.0. I created the user and granted the exact same permissions on this database. However, everytime I attempt to execute the triggers, or anything else that uses DBMS_XMLDOM packages, I get the following error:
    doc dbms_xmldom.DOMDocument;
    ERROR at line 3:
    ORA-06550: line 3, column 11:
    PLS-00201: identifier 'DBMS_XMLDOM.DOMDOCUMENT' must be declared
    I did not create the application database instance on the Solaris machine, but from what I've talked with the DBA, it was created as a general database, which is how I created my test databases. I also verified that the users in both databases have Execute on SYS.XMLDOM granted.
    Any ideas on why I might be getting this error?
    Thanks,
    Andrew

    When I try the describe, it says object not found. If I go into OEM, I don't see that package either. Again, I didn't create that database, but I thought the XML DB stuff was installed by default with the database. Is there a way to add that package after the database is created?
    Thanks,
    Andrew

  • Dbms_xmldom package results in ORA-31020

    Hi,
    I have the following procedure which compiles correct:
    CREATE OR REPLACE procedure vbk_selproc_doc is
    queryctx dbms_xmlquery.ctxtype;
    result varchar2(30000);
    header varchar2(1000);
    footer varchar2(1000);
    body varchar2(20000);
    line VARCHAR2(2000);
    var XMLtype;
    doc dbms_xmldom.domdocument;
    docelem dbms_xmldom.domelement;
    node dbms_xmldom.domnode;
    childnode dbms_xmldom.domnode;
    nodelist dbms_xmldom.domnodelist;
    buf varchar2(30000);
    begin
    queryctx := dbms_xmlquery.newcontext('select * from jobs');
    dbms_xmlquery.setrowsettag(queryctx, 'opdracht-aanbieding');
    dbms_xmlquery.setrowtag(queryctx, 'opdracht');
    dbms_xmlquery.settagcase(queryctx, 1);
    dbms_xmlquery.setrowidattrName(queryctx, null);
    header := '<?xml version="1.0" encoding="utf-8"?>
    <SOAP-ENV:Envelope
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>';
    body := dbms_xmlquery.getxml(queryctx);
    var := XMLTYPE(body);
    doc := dbms_xmldom.newdomdocument(var);
    docelem := dbms_xmldom.getdocumentelement(doc);
    nodelist := dbms_xmldom.getelementsbytagname(docelem, 'NAME');
    node := dbms_xmldom.item(nodelist, 0);
    childnode := dbms_xmldom.getfirstchild(node);
    dbms_xmldom.writetobuffer(childnode, buf);
    dbms_output.put_line('First Child = ' || buf);
    footer := '</SOAP-ENV:Body>
    </SOAP-ENV:Envelope>' || chr(10);
    result := header || ' ' || body || ' ' || footer;
    loop
    exit when result is null;
    line := substr(result, 1, instr(result, chr(10))-1);
    dbms_output.put_line(line);
    result := substr(result, instr(result, chr(10)) +1 );
    end loop;
    dbms_xmlquery.closecontext(queryctx);
    end;
    When executing i get the following error:
    SQL> exec vbk_selproc_doc;
    BEGIN vbk_selproc_doc; END;
    FOUT in regel 1:
    .ORA-31020: The operation is not allowed, Reason: Invalid pl/sql DOM Node hdl
    ORA-06512: at "XDB.DBMS_XMLDOM", line 715
    ORA-06512: at "XDB.DBMS_XMLDOM", line 735
    ORA-06512: at "FWADMIN.VBK_SELPROC_DOC", line 48
    ORA-06512: at line 1
    What is wrong?
    Regards,
    Joshua

    I get the error on:
    dbms_xmldom.writetobuffer(childnode, buf);
    or when i use dbms_xmldom.removechild(nodelist, childnode)

  • DBMS_XMLDOM Package Sample

    Hello everyone
    I need to generate XML output through PL/SQL. Though I had been successful in using DBMS_XMLGEN package, I need to us DBMS_XMLDOM, as I need create hierarchical xml document (ie., Department .....Department Attributes; Employee ....employee attributes....Employee and its attributes within Department node). I was searching for any samples but could not find any. Any help would be appreciated. Also, if I need to approach it in a different way, please let me know about it.
    Thank you in advance
    VV.

    There are some examples of using DBMS_XMLDOM in the online documentation ...
    http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10790/xdb10pls.htm#sthref1069
    Some other options would be to use XMLType Views, the XMLType functions or schema object types and the object based XMLType constructor ...
    http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10790/xdb14vie.htm#CJIDAFJI
    http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10790/xdb14vie.htm#i1025417
    http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10802/t_xml.htm#1009843
    http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10790/xdb13gen.htm#sthref1166

  • Memory not released using dbms_xmldom. free_document()

    Hi:
    I'm using Oracle 10.2.0 under Windows 2003 server 32 bits (Oracle Dedicated Connection)
    I have a PL/SQL stored function that builds a Dom Document from the result of a SQL query and at the end store its content in a Clob variable which is returned to the caller. I’m using the DBMS_XMLDOM package to manipulate the Dom document and at the end I make a call the dbms_xmldom.free_document (domDoc) to free the resources associated to the Dom Doc.
    For some reason when I run several times the PL/SQL stored function I’ve notice that the PGA keeps growing and is never released even when I call "dbms_xmldom.free_document"
    Here is the pl/sql code:
    FUNCTION  sfLerColCenCarga (pId IN INTEGER, pTipoSerie IN VARCHAR2) RETURN CLOB AS
                CURSOR cCenCarga IS
                  SELECT CgCen.IdCgCen, CgCen.IdX, CgCen.Nom, CgCen.TpS, CgCen.EtI, CgCen.EtF,
                         CgCen.Fnt, CgCen.DtR, CgCen.DtA, CgCen.Arq, CgCen.Obs,
                         PeCad.IdX PeCadIdX
                    FROM CgCen, PeCad
                   WHERE PeCad.IdPeCad = CgCen.IdPeCad
                     AND CgCen.IdCgCen = DECODE(pId, NULL, CgCen.IdCgCen, pId)
                   ORDER BY CgCen.DtA DESC;
                regCenCarga cCenCarga%ROWTYPE;
                -- Atributos para manipular o XML
                domDoc                      DBMS_XMLDOM.DOMDocument;
                noRaiz                      DBMS_XMLDOM.DOMNode;
                noObjeto                    DBMS_XMLDOM.DOMNode;
                noColecaoObjeto             DBMS_XMLDOM.DOMNode;
                e                           DBMS_XMLDOM.DOMElement;
                xmlData                     CLOB;
            BEGIN
                dbms_session.free_unused_user_memory;
                domDoc := DBMS_XMLDOM.newDOMDocument;
                noRaiz := DBMS_XMLDOM.makeNode(domDoc);
                e := DBMS_XMLDOM.createElement(domDoc, 'ColecaoCenCarga');
                noColecaoObjeto := DBMS_XMLDOM.appendChild(noRaiz, DBMS_XMLDOM.makeNode(e));
                OPEN cCenCarga;
                LOOP
                    FETCH cCenCarga INTO regCenCarga;
                    EXIT WHEN cCenCarga%NOTFOUND;
                    e := DBMS_XMLDOM.createElement(domDoc, 'CenCarga');
                    -- Define valores dos atributos do elemento
                    DBMS_XMLDOM.setAttribute (e, 'Id', regCenCarga.IdCgCen);
                    DBMS_XMLDOM.setAttribute (e, 'IdX', TRIM(regCenCarga.IdX));
                    DBMS_XMLDOM.setAttribute (e, 'Nom', TRIM(regCenCarga.Nom));
                    DBMS_XMLDOM.setAttribute (e, 'Fnt', TRIM(regCenCarga.Fnt));
                    DBMS_XMLDOM.setAttribute (e, 'TpS', regCenCarga.TpS);
                    DBMS_XMLDOM.setAttribute (e, 'EtI', TRIM(regCenCarga.EtI));
                    DBMS_XMLDOM.setAttribute (e, 'EtF', TRIM(regCenCarga.EtF));
                    DBMS_XMLDOM.setAttribute (e, 'Aut', TRIM(regCenCarga.PeCadIdX));
                    DBMS_XMLDOM.setAttribute (e, 'Org', 'X');
                    DBMS_XMLDOM.setAttribute (e, 'OrgX', 'Externa');
                    DBMS_XMLDOM.setAttribute (e, 'DtR', TO_CHAR(regCenCarga.DtR,'dd/mm/yyyy HH24:MI'));
                    DBMS_XMLDOM.setAttribute (e, 'DtA', TO_CHAR(regCenCarga.DtA,'dd/mm/yyyy HH24:MI'));
                    DBMS_XMLDOM.setAttribute (e, 'Arq', TRIM(regCenCarga.Arq));
                    DBMS_XMLDOM.setAttribute (e, 'Obs', TRIM(regCenCarga.Obs));
                    noObjeto := DBMS_XMLDOM.appendChild(noColecaoObjeto, DBMS_XMLDOM.makeNode(e));
                END LOOP;
                CLOSE cCenCarga;
                dbms_lob.createTemporary(xmlData, TRUE, DBMS_LOB.CALL);
                DBMS_XMLDOM.writeToClob(domDoc, xmlData);
                DBMS_XMLDOM.freeDocument(domDoc);
                RETURN xmlData;
            END;Could somebody please tell me if I should call some other method to release my memory or is it a leak in the DBMS_XMLDOM package?
    Thanks in advance,
    André Granville

    You left off the final number in your version, but I'm going to assume it is .1 - .3. You are running into a bug in Oracle.
    http://anononxml.blogspot.com/2010/09/memory-leaks.html
    I would suggest upgrading to .4 or .5 (should be out for all versions) as the first step to fix your problem.

  • ORA-07445 and XDB.DBMS_XMLDOM

    Hi,
    I am receiving the following messages in the alert log:
    Errors in file d:\oracle\ora10g\dumps\udump\prod_ora_5116.trc:
    ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [0x3681AB1] [] [] [] []
    ORA-06510: PL/SQL: unhandled user-defined exception
    When I review the trace file, I see this:
    *** SERVICE NAME:(SYS$USERS) 2006-07-26 13:06:10.246
    *** SESSION ID:(80.5257) 2006-07-26 13:06:10.246
    *** 2006-07-26 13:06:10.246
    ksedmp: internal or fatal error
    ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [0x3681AB1] [] [] [] []
    ORA-06510: PL/SQL: unhandled user-defined exception
    Current SQL statement for this session:
    BEGIN Pack_Core_Api_Main.Proc_Core_Api_Main(:1,:2); END;
    ----- PL/SQL Call Stack -----
    object line object
    handle number name
    8F21A048 4644 package body XDB.DBMS_XMLDOM
    8F21A048 4667 package body XDB.DBMS_XMLDOM
    8F196B1C 1516 package body OSIBANK.PACK_CORE_API_PERSONMAINT
    8D03B614 361 package body OSIBANK.PACK_CORE_API_ROUTER
    8D03B614 128 package body OSIBANK.PACK_CORE_API_ROUTER
    8F239C6C 134 package body OSIBANK.PACK_CORE_API_MAIN
    8DB36A64 1 anonymous block
    --- snip ---
    It seems to me the exception/error is occurring in package body XDB.DBMS_XMLDOM, but I am not certain.
    My database is ORACLE V10.1.0.2.0.
    Any thoughts?
    Thank you,
    Bret

    I am in the process of trying to find out just that....where it's called from and what is sent to it. Here is the next bit from the trace file though. Please let me know if you'd like to see more of it.
    Thank you,
    Bret
    *** SERVICE NAME:(SYS$USERS) 2006-07-26 13:06:10.246
    *** SESSION ID:(80.5257) 2006-07-26 13:06:10.246
    *** 2006-07-26 13:06:10.246
    ksedmp: internal or fatal error
    ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [0x3681AB1] [] [] [] []
    ORA-06510: PL/SQL: unhandled user-defined exception
    Current SQL statement for this session:
    BEGIN Pack_Core_Api_Main.Proc_Core_Api_Main(:1,:2); END;
    ----- PL/SQL Call Stack -----
    object line object
    handle number name
    8F21A048 4644 package body XDB.DBMS_XMLDOM
    8F21A048 4667 package body XDB.DBMS_XMLDOM
    8F196B1C 1516 package body OSIBANK.PACK_CORE_API_PERSONMAINT
    8D03B614 361 package body OSIBANK.PACK_CORE_API_ROUTER
    8D03B614 128 package body OSIBANK.PACK_CORE_API_ROUTER
    8F239C6C 134 package body OSIBANK.PACK_CORE_API_MAIN
    8DB36A64 1 anonymous block
    ----- Call Stack Trace -----
    calling call entry argument values in hex
    location type point (? means dubious value)
    qmxdAdoptNode+1819  CALLrel  qmxRemoveChild+0 1E237380 0 0 1E237380 995FD5C
    1E237380 995B7AC 9958C40 0 1
    qmxdplsdocadoptno CALLrel _qmxdAdoptNode+0     C57E6C0 995B7AC 0 9958C40
    de+174
    _spefcpfa+357        CALLreg  00000000            
    spefmccallstd+661   CALLrel  spefcpfa+0
    pextproc+88         CALLrel  spefmccallstd+0 1F26D450 1F26D380 1F26D248
    1F26D1C0 A26B15C
    peftrusted+138      CALLrel  pextproc+0 1F26D450 1F26D380 1F26D248
    1F26D1C0
    _psdexsp+115         CALLreg  00000000             0
    _rpiswu2+368         CALLreg  00000000             1F26D15C
    psdextp+439         CALLrel  rpiswu2+0 99890D4C 27 1F26D110 2
    1F26D0F4 27 1F26D130 0
    214B410 0 1F26D15C 0
    _pefccal+361         CALLreg  00000000             1F26D818 1F26D380 1F26D248 0
    20003 1F26D450 60B103F0
    pefcal+125          CALLrel  pefccal+0 1E237380
    pevmFCAL+191 CALLrel _pefcal+0           
    pfrinstrFCAL+70 CALLrel pevmFCAL+0
    pfrrunno_tool+51 CALL??? 00000000
    pfrrun+1834         CALLrel  pfrrun_no_tool+0 D56E5A8 8EAD2CFA D56E5E4
    plsqlrun+1051 CALLrel _pfrrun+0            D56E5A8
    peicnt+179          CALLrel  plsql_run+0 D56E5A8 1 0
    kkxexe+477          CALLrel  peicnt+0
    opiexe+4896         CALLrel  kkxexe+0 8DB36A64
    kpoal8+1705         CALLrel  opiexe+0 49 3 1F26E070
    _opiodr+977          CALLreg  00000000             5E 14 1F26E7D0
    _ttcpip+1827         CALLreg  00000000             5E 14 1F26E7D0 0
    _opitsk+1098         CALL???  00000000            
    opiino+938          CALLrel  opitsk+0 0 0 1E23DD30 97EFDF8 B9 0
    _opiodr+977          CALLreg  00000000             3C 4 1F26FBC0
    opidrv+479          CALLrel  opiodr+0 3C 4 1F26FBC0 0
    sou2o+45            CALLrel  opidrv+0 3C 4 1F26FBC0
    opimai+237          CALLrel  sou2o+0
    OracleThreadStart@  CALLrel  opimai+0
    4+899
    77E66060 CALLreg 00000000
    --------------------- Binary Stack Dump ---------------------
    -- snip ---

  • Problem with dbms_xmldom.makedocumentfragment in 10.2.0.4 (ORA:31183)

    Hi!
    After a upgrade from 9.2.0.8 to 10.2.0.4 the following procedure has stopped working.
    -- PROC START --
    procedure lp_daten(p_node IN dbms_xmldom.DOMNode) AS
    BEGIN
    if dbms_xmldom.isnull(p_node)
    then return;
    end if;
    dbms_lob.createTemporary(l_interpretation,TRUE);
    l_xsldoc := dbms_xmldom.newDOMDocument(xmltype.createXML(
    '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' ||
    '<xsl:template match="interpretation">' ||
    '<xsl:copy-of select="* | text()"/>' ||
    '</xsl:template>' ||
    '</xsl:stylesheet>'));
    dbms_xslprocessor.valueOf(p_node,'name/text()',l_name);
    l_node := dbms_xslprocessor.selectSingleNode(p_node,'child::interpretation');
    --DBMS_OUTPUT.put_line('Node name = ' || DBMS_XMLDOM.getNodeName(l_node));
    --DBMS_OUTPUT.put_line('Node value = '|| DBMS_XMLDOM.getNodeValue(l_node));
    --DBMS_OUTPUT.put_line('Node type = ' || DBMS_XMLDOM.getNodeType(l_node));
    l_xmlinterpret := dbms_xmldom.MAKEDOCUMENTFRAGMENT(l_node);
    l_xslstylesheet := dbms_xslprocessor.newStylesheet(l_xsldoc, null);
    l_xslproc := dbms_xslprocessor.newProcessor;
    dbms_xslprocessor.processXSL(l_xslproc, l_xslstylesheet, l_xmlinterpret, l_interpretation);
    dbms_xslprocessor.freeProcessor(l_xslproc);
    dbms_xmldom.freeDocument(l_xsldoc);
    -- dbms_output.put_line ('Uni: ' || l_univ);
    -- dbms_output.put_line ('Jahr: ' || l_jahr);
    -- dbms_output.put_line ('Interpretation: ' || l_interpretation || ' Lange: ' || length(l_interpretation));
    -- dbms_output.put_line ('Name: ' || l_name);
    insert into wbjahrunivkz_tmp
    (liefidf,jahr,univ,kzidf,interpretation,bearblzt,bdatzeitlzt)
    values
    (l_liefidf,l_jahr,l_univ,l_name,replace(l_interpretation,'<dummy/>',''),user,sysdate);
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line ('Exception in lp_daten: ' || substr(sqlerrm, 0, 250));
    raise;
    END lp_daten;
    -- PROC END --
    It fails on the line "l_xmlinterpret := dbms_xmldom.MAKEDOCUMENTFRAGMENT(l_node);" because xdb can't cast a documentNode to a documentFragment. But documentation says this should work.
    I get the following error:
    ORA-31183: cannot cast into given type...
    What goes wrong here?
    Thanks
    Markus

    Markus
    Additional checks were added to throw ORA-31183 after 9.2.0.8.0. The intent of make* functions is to just cast DOM Types back and forth to DOMNode, not to change them from one type to another via a DOMNode. For this testcase, you should create a new document fragment and append the l_node (or its copy) as a child of that.
    Asha

  • Using dbms_xmldom to load large xml

    Hi,
    I am using dbms_xmldom to load the xml of size 600 MB. Its taking around 7 hours to load the xml.
    Please provide the tips or tricks to tune the dbms_xmldom code. Quick help will be appreciated. Thanks !!

    55e6744f-71c3-4d9d-a1a9-772c14ab90f9 wrote:
    Please help. Its urgent.
    No it's not. And it's very rude of you to assume so.
    Read: Re: 2. How do I ask a question on the forums?
    In answer to your question, I agree with Odie, you don't want to be using XML DOM for this.  See Mark Drake's (mdrake) answers on this thread over in the XMLDB forum...
    Re: XML file processing into oracle

  • DBMS_XMLDOM.WRITETOFILE

    Hi,
    I am creating a PL/SQL that should read from an XML file in XML DB Repository, create an XML file out of it.
    The lines I have in PL/SQL to create the XML file are:
    v_domdoc DBMS_XMLDOM.DOMDOCUMENT;
    v_domelement DBMS_XMLDOM.DOMELEMENT;
    v_domnode DBMS_XMLDOM.DOMNODE;
    v_domdoc := DBMS_XMLDOM.NEWDOMDOCUMENT();
    l_string := '/PUBLIC/OUT/AC.XML';
    DBMS_XMLDOM.WRITETOFILE(v_domnode, l_string);
    When I run the PL/SQL, I get the following error at WRITETOFILE:
    ORA-29280: invalid directory path
    ORA-06512: at "SYS.UTL_FILE", line 33
    ORA-06512: at "SYS.UTL_FILE", line 436
    ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 217
    ORA-29280: invalid directory path
    ORA-29280: invalid directory path
    What must I do in order to create the file successfully? By the way, '/PUBLIC/OUT' folder exists and AC.XML file does not exist.
    Thanks in advance
    Bharathan

    Sorry, I must have added these details in the first place.
    Yes, I do have read/write access at OS (Windows Vista Home Premium). I am trying to create the file in XML DB Repository.
    Following are the DB details:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
    PL/SQL Release 10.2.0.3.0 - Production
    CORE     10.2.0.3.0     Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    I am using SQL*Developer to develop the PL/SQL. Please bear with me if I am not providing you enough details. Appreciate your help coming my way.
    Regards
    Bharathan

  • DBMS_XMLDOM.getdocumentelement failing...

    Hi,
    I have written a generic function which takes 2 XMLType as input (parent, child) and returns a XMLType by appending child inside parent. I am using dbms_XMLDOM for this.
    eg. if parent = <a></a> and child <b></b> then output would be <a><b></b></a>.
    Its working fine in normal way. But its failing if my child has XML tag with namespace eg. <str:b>. 'str' namespace is declared inside parent.
    Pls. suggest work around for this.

    Hi !
    Well Ok . Generally your dba is right. Your procedure should be very well tested before you runs it as a job in production. As a developer you have some tools to catch the errors in procedure as .. writing some messages
    in some log table, sending a mail .... , but you should built in your procedure exception handler of course.
    read this article written by Steven Feuerstein. It deals with dbms_utility.format_error_stack and dbms_utility.format_error_backtrace with some examples
    http://www.oracle.com/technology/oramag/oracle/05-mar/o25plsql.html
    You can also consider sending a mail to "application keeper" if something is going wrong with the job(procedure) ..
    Anyway in the procedure itself you should take a lot of care how to react in case of failure. Because it is not the JOB , but your procedure runs errorneous ..
    Back to your direct question
    in exception hanlder you can use SQLERRM , SQLCODE , error_stack , call_stack ...
    It's a good practice that each procedure has an exception handler as which again must be very well written ( not to produce new exceptions )
    procedure test_proc
    begin
    exception
       when <exception qualifier 1> then
           <insert into my_log ( ... ) values ( .... )>
       when <exception qualifier 2> then
           <send an email to me>
       when others then
           <send an email to someone>
    end;T
    Edited by: ttt on 16.3.2010 23:14

  • Dbms_XMLDom.setData/appendData/insertData

    I try to understand, how can I make XML documents, export into file, etc. But I have some mistake. Example:
    SET SERVEROUTPUT ON;
    DECLARE
    doc dbms_XMLDom.DOMDocument;
    main_dom_node dbms_XMLDom.DOMNode;
    root_dom_node dbms_XMLDom.DOMNode;
    vt_dom_node dbms_XMLDom.DOMNode;
    vdat_dom_node dbms_XMLDom.DOMNode;
    data_dom_node dbms_XMLDom.DOMNode;
    text_dom_node dbms_XMLDom.DOMNode;
    root_elmt dbms_XMLDom.DOMElement;
    vt_elmt dbms_XMLDom.DOMElement;
    vdat_elmt dbms_XMLDom.DOMElement;
    data_elmt dbms_XMLDom.DOMElement;
    data_cont dbms_XMLDom.DOMCharacterData;
    buf VARCHAR2(4000);
    BEGIN
    doc := dbms_XMLDom.newDOMDocument;
    dbms_XMLDom.setVersion(doc,'1.0');
    main_dom_node := dbms_XMLDom.makeNode(doc);
    root_elmt := dbms_XMLDom.createElement(doc, 'FirstDokumentum');
    root_dom_node := dbms_XMLDom.appendChild( main_dom_node, dbms_XMLDom.makeNode(root_elmt));
    vt_elmt := dbms_XMLDom.createElement(doc,'FirstGroup');
    vt_dom_node := dbms_XMLDom.appendChild( root_dom_node, dbms_XMLDom.makeNode(vt_elmt));
    vdat_elmt := dbms_XMLDom.createElement(doc,'DataTags');
    vdat_dom_node := dbms_XMLDom.appendChild(vt_dom_node, dbms_XMLDom.makeNode(vdat_elmt));
    data_elmt := dbms_XMLDom.createElement(doc,'DataTag');
    data_dom_node := dbms_XMLDom.appendChild(vdat_dom_node, dbms_XMLDom.makeNode(data_elmt));
    data_cont := dbms_XMLDom.makeCharacterData(data_dom_node);
    dbms_XMLDom.setData( data_cont,'This_is_data');
    dbms_XMLDom.appendData( data_cont,'And_this_is_too');
    dbms_XMLDom.insertData( data_cont,1,'This_will_be_inserted'); vt_elmt := dbms_XMLDom.createElement(doc,'SecondGroup');
    vt_dom_node := dbms_XMLDom.appendChild( root_dom_node, dbms_XMLDom.makeNode(vt_elmt));
    dbms_XMLDom.writetobuffer(doc, buf);
    DBMS_OUTPUT.PUT_LINE(buf);
    END;
    Answer from SQL+:
    <FirstDokumentum>
    <FirstGroup>
    <DataTags>
    <DataTag/>
    </DataTags>
    </FirstGroup>
    <SecondGroup/>
    </FirstDokumentum>
    Why <DataTag> empty, why not <DataTag>This_is_data...</DataTag>
    Thx 4 hlp.
    Steve

    solution:
    elem := dbms_XMLDom.createElement(doc,'Ar');
    text := dbms_XMLDom.createTextNode(doc,'5678.00');
    node := dbms_XMLDom.appendChild(dbms_XMLDom.makeNode(elem), dbms_XMLDom.makeNode(text));
    DBMS_OUTPUT.PUT_LINE( dbms_XMLDom.getData( dbms_XMLDom.makeCharacterData( node ) ) );
    dbms_XMLDom.setData( dbms_XMLDom.makeCharacterData( node ) , '1234');
    DBMS_OUTPUT.PUT_LINE( dbms_XMLDom.getData( dbms_XMLDom.makeCharacterData( node ) ) );
    dbms_XMLDom.appendData( dbms_XMLDom.makeCharacterData( node ) , '5678');
    DBMS_OUTPUT.PUT_LINE( dbms_XMLDom.getData( dbms_XMLDom.makeCharacterData( node ) ) );
    dbms_XMLDom.insertData( dbms_XMLDom.makeCharacterData( node ) , 4 , '-ABC-');
    DBMS_OUTPUT.PUT_LINE( dbms_XMLDom.getData( dbms_XMLDom.makeCharacterData( node ) ) );
    node := dbms_XMLDom.appendChild( vdat_dom_node , dbms_XMLDom.makeNode(elem));
    SQLPlus:
    SQL> SET SERVEROUTPUT ON
    SQL> EXECUTE l1.dom_build
    5678.00
    1234
    12345678
    1234-ABC-5678
    A PL/SQL eljárás sikeresen befejezõdött.
    SQL>
    Thx.
    István

  • Dbms_xmldom.getLength is working incorrectly

    Hi,
    Seems that there's some kind of a limit while using dbms_xmldom.getLength.
    If there are more then 65535 childenodes getlength is starting to count from the zero again.
    SQL> DECLARE
      2     l_doc  dbms_xmldom.DOMDocument;
      3     l_list dbms_xmldom.DOMNodeList;
      4     l_clob clob;
      5  BEGIN
      6     dbms_lob.createTemporary(l_clob,TRUE);
      7     dbms_lob.append(l_clob,'<a>');
      8     FOR i IN 1..65535 LOOP
      9        dbms_lob.append(l_clob,'<b>1</b>');
    10     END LOOP;
    11     dbms_lob.append(l_clob,'</a>');
    12     l_doc:=dbms_xmldom.newdomdocument(l_clob);
    13     l_list:=dbms_xmldom.getChildNodes(dbms_xmldom.getFirstChild(dbms_xmldom.MakeNode(l_doc)));
    14     dbms_output.put_line('length='||dbms_xmldom.getLength(l_list));
    15     dbms_lob.freetemporary(l_clob);
    16  END;
    17  /<b>length=65535</b>
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:04.47
    SQL> DECLARE
      2     l_doc  dbms_xmldom.DOMDocument;
      3     l_list dbms_xmldom.DOMNodeList;
      4     l_clob clob;
      5  BEGIN
      6     dbms_lob.createTemporary(l_clob,TRUE);
      7     dbms_lob.append(l_clob,'<a>');
      8     FOR i IN 1..65537 LOOP
      9       dbms_lob.append(l_clob,'<b>1</b>');
    10     END LOOP;
    11     dbms_lob.append(l_clob,'</a>');
    12     l_doc:=dbms_xmldom.newdomdocument(l_clob);
    13     l_list:=dbms_xmldom.getChildNodes(dbms_xmldom.getFirstChild(dbms_xmldom.MakeNode(l_doc)));
    14     dbms_output.put_line('length='||dbms_xmldom.getLength(l_list));
    15     dbms_lob.freetemporary(l_clob);
    16  END;
    17  /<b>length=1</b>
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:05.13

    Hi,
    64K nodes it the limit. I'm suprised it didn't throw an error..
    I'm guessing that node size throws an error but not how many nodes to you have.
    Even 100000 doesn't throw an error.
    Seems that if there are more than 65535 nodes, then your node list size becomes mod(x,65536) where x is initial number of nodes.
    In the first procedure we have 100000 nodes and if I later print out the values we can see,
    that the list is cutted from 34464.
    In the second procedure we have 65535 nodes and this one is not cutted.
    So the problem is not in getLength but rather in getting the entire list.
    SQL>
    SQL> DECLARE
      2    l_doc  dbms_xmldom.DOMDocument;
      3    l_list dbms_xmldom.DOMNodeList;
      4    l_node dbms_xmldom.domnode;
      5    l_value NUMBER;
      6    l_clob clob;
      7  BEGIN
      8    dbms_lob.createTemporary(l_clob,TRUE);
      9    dbms_lob.append(l_clob,'<a>');
    10    FOR i in 0..100000 LOOP
    11      dbms_lob.append(l_clob,'<b i="'||i||'"></b>');
    12    END LOOP;
    13    dbms_lob.append(l_clob,'</a>');
    14    l_doc:=dbms_xmldom.newdomdocument(l_clob);
    15    l_list:=dbms_xmldom.getElementsByTagName(l_doc,'b');
    16    FOR i IN 0..99999 LOOP
    17      l_node:=dbms_xmldom.item(l_list,i);
    18      l_value:=dbms_xmldom.getattribute(dbms_xmldom.makeelement(l_node),'i');
    19      IF l_value IS NULL THEN
    20        --previous value
    21        l_node:=dbms_xmldom.item(l_list,i-1);
    22        l_value:=dbms_xmldom.getattribute(dbms_xmldom.makeelement(l_node),'i');
    23        dbms_output.put_line('No value='||i||' and previous value was '||l_value);
    24        EXIT;
    25      END IF;
    26    END LOOP;
    27  END;
    28  /
    No value=34465 and previous value was 34464                                    
    PL/SQL procedure successfully completed.
    SQL> DECLARE
      2    l_doc  dbms_xmldom.DOMDocument;
      3    l_list dbms_xmldom.DOMNodeList;
      4    l_node dbms_xmldom.domnode;
      5    l_value NUMBER;
      6    l_clob clob;
      7  BEGIN
      8    dbms_lob.createTemporary(l_clob,TRUE);
      9    dbms_lob.append(l_clob,'<a>');
    10    FOR i in 0..65534 LOOP
    11      dbms_lob.append(l_clob,'<b i="'||i||'"></b>');
    12    END LOOP;
    13    dbms_lob.append(l_clob,'</a>');
    14    l_doc:=dbms_xmldom.newdomdocument(l_clob);
    15    l_list:=dbms_xmldom.getElementsByTagName(l_doc,'b');
    16    FOR i IN 0..65535 LOOP
    17      l_node:=dbms_xmldom.item(l_list,i);
    18      l_value:=dbms_xmldom.getattribute(dbms_xmldom.makeelement(l_node),'i');
    19      IF l_value IS NULL THEN
    20        --previous value
    21        l_node:=dbms_xmldom.item(l_list,i-1);
    22        l_value:=dbms_xmldom.getattribute(dbms_xmldom.makeelement(l_node),'i');
    23        dbms_output.put_line('No value='||i||' and previous value was '||l_value);
    24        EXIT;
    25      END IF;
    26    END LOOP;
    27  END;
    28  /
    No value=65535 and previous value was 65534                                    
    PL/SQL procedure successfully completed.
    SQL> spool off;

  • Dbms_xmldom.cloneNode always deep ?

    Hi,
    i'm unable to see any difference between :
    1. dbms_xmldom.cloneNode( node, false )
    2. dbms_xmldom.cloneNode( node, true )
    i always get a complete copy of the original node.
    Any suggestion ?
    thanks
    Alessandro Scotti

    9.2.0.1.0 is not supported for any XML DB functionality. Please upgrade to at least 9.2.0.3.0, or ideally 9.2.0.5.0 or 10.1.0.2.0 and try again

Maybe you are looking for