XMLDOM + XMLTYPE

Hello.
I need to generate XML document with special structure from Database 11g.
I am using DBMS_XMLDOM to ganerate structure.
<GenericData
xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v1_0/message"
xmlns:common="http://www.SDMX.org/resources/SDMXML/schemas/v1_0/common"
xmlns:compact="http://www.SDMX.org/resources/SDMXML/schemas/v1_0/compact"
xmlns:cross="http://www.SDMX.org/resources/SDMXML/schemas/v1_0/cross"
xmlns:generic="http://www.SDMX.org/resources/SDMXML/schemas/v1_0/generic"
xmlns:query="http://www.SDMX.org/resources/SDMXML/schemas/v1_0/query"
xmlns:structure="http://www.SDMX.org/resources/SDMXML/schemas/v1_0/structure"
xmlns:utility="http://www.SDMX.org/resources/SDMXML/schemas/v1_0/utility"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.SDMX.org/resources/SDMXML/schemas/v1_0/message SDMXMessage.xsd">
<Dataset>
<generic:Series>
<generic:Series>
<generic:Series>
<generic:Series>
</Dataset>
</GenericData>
One of the main nodes is Dataset.
I am using select XMLELEMENT("Dataset", .........) INTO Q FROM EMS_001
WHERE Q has XMLType.
How i can add XMLType to XMLDOM document as node?

Believe me, you should get rid of all this DOM stuff, you'll have more luck doing the whole thing with SQL/XML functions only.
Not only you'll have a clearer, easier to debug code but also a lot more scalable when applied on large datasets.I Thought about it. But i have more than 2 data sources and can't get them all in 1 select.
I find a best solution for myself:
DECLARE
DOC DBMS_XMLDOM.DOMDOCUMENT;
TAGDOC DBMS_XMLDOM.DOMDOCUMENT;
ROOT_ELEMENT DBMS_XMLDOM.DOMELEMENT;
ELEM DBMS_XMLDOM.DOMELEMENT;
ROOT_NODE DBMS_XMLDOM.DOMNODE;
NODE DBMS_XMLDOM.DOMNODE;
C CLOB;
TAG XMLType;
BEGIN
DOC := DBMS_XMLDOM.CREATEDOCUMENT('http://www.w3.org/2001/XMLSchema', NULL, NULL);
DBMS_XMLDOM.SETVERSION(DOC, '1.0');
ROOT_ELEMENT := DBMS_XMLDOM.CREATEELEMENT(DOC, 'GenericData', 'xmlns');
DBMS_XMLDOM.SETATTRIBUTE(ROOT_ELEMENT, 'xmlns', 'http://www.SDMX.org/resources/SDMXML/schemas/v1_0/message');
DBMS_XMLDOM.SETATTRIBUTE(ROOT_ELEMENT, 'xmlns:generic', 'http://www.SDMX.org/resources/SDMXML/schemas/v1_0/generic');
ROOT_NODE := DBMS_XMLDOM.MAKENODE(ROOT_ELEMENT);
NODE := DBMS_XMLDOM.MAKENODE(DOC);
NODE := DBMS_XMLDOM.APPENDCHILD(NODE, ROOT_NODE);
---------------------- HEADER TAG -------------------
SELECT XMLELEMENT("Header", XMLATTRIBUTES('singHead' AS "Id"),
XMLELEMENT("ID", -944960705),
XMLELEMENT("Test", 'false'),
XMLELEMENT("Truncated", 'false'),
XMLELEMENT("Prepared", '2011-01-27T04:32:42'),
XMLELEMENT("Extracted", '2011-01-27T04:32:42'),
XMLELEMENT("Sender", XMLATTRIBUTES('FTS' AS "id"),
XMLELEMENT("Name", XMLATTRIBUTES('en' AS "xml:lang"), 'FFFF'),
XMLELEMENT("Name", XMLATTRIBUTES('ru' AS "xml:lang"), 'ФФФФ'),
XMLELEMENT("Contact",
XMLELEMENT("Name", XMLATTRIBUTES('ru' AS "xml:lang"), 'JOHN'),
XMLELEMENT("URI", 'mailto:[email protected]'))),
XMLELEMENT("Receiver", XMLATTRIBUTES('1' AS "id"),
XMLELEMENT("Name", XMLATTRIBUTES('ru' AS "xml:lang"), 'ФФФФ'),
XMLELEMENT("Contact",
XMLELEMENT("Name", XMLATTRIBUTES('ru' AS "xml:lang"), 'JOHN'),
XMLELEMENT("Telephone", '+000.000.0000'))),
XMLELEMENT("DataSetAgency", 1),
XMLELEMENT("DataSetID", 1812022)
) INTO TAG FROM DUAL;
TAGDOC := DBMS_XMLDOM.NEWDOMDOCUMENT(TAG);
ELEM := DBMS_XMLDOM.GETDOCUMENTELEMENT(TAGDOC);
ELEM := DBMS_XMLDOM.MAKEELEMENT(DBMS_XMLDOM.IMPORTNODE(DOC,DBMS_XMLDOM.MAKENODE(ELEM),TRUE));
ELEM := DBMS_XMLDOM.MAKEELEMENT(DBMS_XMLDOM.APPENDCHILD(DBMS_XMLDOM.MAKENODE(ROOT_ELEMENT),DBMS_XMLDOM.MAKENODE(ELEM)));
---------------------- HEADER TAG -------------------
---------------------- DATASET TAG ------------------
TAG := XMLTYPE('<DataSet xmlns:generic="http://www.SDMX.org/resources/SDMXML/schemas/v1_0/generic">
     <generic:Series>
          <generic:SeriesKey>
               <generic:Value concept="okato" value="643"/>
               <generic:Value concept="uslug" value="1"/>
          </generic:SeriesKey>
          <generic:Attributes>
               <generic:Value concept="EI" value="percent"/>
               <generic:Value concept="PERIOD" value="year"/>
          </generic:Attributes>
          <generic:Obs>
               <generic:Time>1995</generic:Time>
               <generic:ObsValue value="108,6"/>
          </generic:Obs>
     </generic:Series>
</DataSet>
TAGDOC := DBMS_XMLDOM.NEWDOMDOCUMENT(TAG);
ELEM := DBMS_XMLDOM.GETDOCUMENTELEMENT(TAGDOC);
DBMS_XMLDOM.REMOVEATTRIBUTE(ELEM, 'xmlns:generic');
ELEM := DBMS_XMLDOM.MAKEELEMENT(DBMS_XMLDOM.IMPORTNODE(DOC,DBMS_XMLDOM.MAKENODE(ELEM),TRUE));
ELEM := DBMS_XMLDOM.MAKEELEMENT(DBMS_XMLDOM.APPENDCHILD(DBMS_XMLDOM.MAKENODE(ROOT_ELEMENT),DBMS_XMLDOM.MAKENODE(ELEM)));
---------------------- DATASET TAG ------------------
DBMS_LOB.CREATETEMPORARY(C, TRUE, DBMS_LOB.SESSION);
DBMS_XMLDOM.WRITETOCLOB(DOC, C);
INSERT INTO PROBA VALUES (C);
COMMIT;
DBMS_XMLDOM.FREENODE(NODE);
DBMS_XMLDOM.FREENODE(ROOT_NODE);
DBMS_XMLDOM.FREEDOCUMENT(TAGDOC);
DBMS_XMLDOM.FREEDOCUMENT(DOC);
END;
As you see i can get nodes data from SELECT and add them as nodes to main XML.
Edited by: Alexys on 10.04.2012 12:04
Edited by: Alexys on 10.04.2012 12:05
Edited by: Alexys on 10.04.2012 12:06

Similar Messages

  • XMLTYPE to XMLDOM conversion

    I have a table with records that contain an field of type "xmltype"
    I would like to read such a record and convert that (xmltype) field into an item with the structure of "xmldom.domdocument"
    Can anyone help ?

    You may stand a better chance at the XML DB forum: XML DB

  • Is it possible to add variable defined as xmltype to an xmldom node?

    Hi,
    I'm trying to produce a complex XML document that doesn't lend itself well to using SQL XML functions (xmlagg, xmlelement, etc.) because various disparate data needs to be pulled together via seperate queries and then stuck into the final document in the correct spots.
    So I've resorted to using the convoluted pl/sql xmldom functions. What I'm wondering though is if it is possible to take data in an xmltype variable and somehow append it as a node within my xml document? Something as in the following pseudo code:
    begin
    doc := xmldom.newDOMDocument;
    main_node := xmldom.makeNode (doc);
    select xmlelement("Address",...) -- more xmlelements containing related address info (street, city, etc.)
    into l_address
    from ...;
    new_node := xmldom.appendChild (main_node, xmldom.makeNode (l_address));
    end;
    If possible, this would save me a tremendous amount of time from having to code every element and attributes via the xmldom functions.
    Thanks,
    Alan

    I've done the same scenario you are describing, shove XML defined in an XMLType into a DOMDocument. I munged the code to hide system specific references so the code works, just not as pasted here. The document is being built in o_response_doc and goes after the node previously built in l_rsp_msg_nd. The input is l_xmltype. May be a better way but I never found one and came up with this based on the Oracle documentation and trial and error.
        -- Convert the XMLType to a DOMDocument so we can extract the needed node
        --  and insert it into the response DOMDocument
        l_temp_domdoc := dbms_xmldom.newdomdocument(l_xmltype);
        l_inq_nodelist := dbms_xmldom.getelementsbytagname(l_temp_domdoc,
                                                           'DesiredXMLTypeNodeName');
        l_inq_nl_len := xmldom.getlength(l_inq_nodelist);
        IF l_inq_nl_len > 0 THEN
           -- Take the node above and adopt it into the response document
           l_temp2_nd := dbms_xmldom.importNode(o_response_doc,
                                                dbms_xmldom.item(l_inq_nodelist, 0),
                                                TRUE);
           -- Remove the a: namespace that was autoadded.  (this was defined in the l_xmltype XML)
           dbms_xmldom.removeattribute(dbms_xmldom.makeelement(l_temp2_nd),
                                       <ns_pfx>,
                                       <ns_uri>);
           -- Put the node in the correct position in the response document                                          
           l_temp2_nd := xdb.dbms_xmldom.appendChild(l_rsp_msg_nd, l_temp2_nd);
        END IF;
        dbms_xmldom.freeDocument(l_temp_domdoc);

  • Xmldom.writetoclob hanging forever when writing a domnode to a temp clob

    Hi
    Wondering has anyone come across anything similar (or know a work around)
    1. Basically the the procedure below loads an XML file. (OK)
    2. Removes reference to external dtd, ref was causing and error (OK)
    3. Parses the XML (OK)
    4. Gets a list of the "item" tags (OK) - should be up to 500 item elements in XML
    5. Loops on all elements
    a. writes node to temp clob *(PROBLEM HERE)*
    b. Creates xmltype from clob (OK)
    c. transforms xmltype and assigns to another xmltype (OK)
    d. inserts new xmltype (OK)
    This procedure is used by a threaded os java app to load thousands of files to db.
    It works fine 99% of the time but for some files the procedure is hanging at (5.a : write domnode to clob using xmldom.writetoclob)
    I am absolutely sure the problem is due to the characters in the domnode as all files that have hung on processing contain these bizarre characters,
    the db character set is Unicode AL32UTF8 so it should be able to handle almost anything, saying that, if the it is a prob with the characters then why does
    the loadclobfromfile procedure succeed.
    Developed on Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit
    I have no prob rejecting node and continue processing but procedure just hangs and i have to kill the thread on the os.
    Is there a way to
    1. Test for invalid AL32UTF8 chars and skip on error.
    or
    2. Get around the xmldom.writetoclob procedure and create an xmltype from the xmldom.domnode (i tried to convert domnode -> domdocument -> xmltype, no joy)
    or
    Open to suggestions
    PROCEDURE
    PROCEDURE process_blog_xml_file (
          p_file_name     IN   VARCHAR2,
          p_insert_date   IN   VARCHAR2,
          p_dir           IN   VARCHAR2 DEFAULT NULL
       IS
          newsurl        VARCHAR2 (80);
          parser         xmlparser.parser;
          newsxml        xmldom.domdocument;
          titles         xmldom.domnodelist;
          titles_found   NUMBER;
          curnode        xmldom.domnode;
          textchild      xmldom.domnode;
          dest_clob      CLOB;
          l_temp_clob    CLOB;
          src_clob       BFILE         := BFILENAME (g_zip_file_dir, p_file_name);
          dst_offset     NUMBER             := 1;
          src_offset     NUMBER             := 1;
          lang_ctx       NUMBER             := DBMS_LOB.default_lang_ctx;
          warning        NUMBER;
          l_xml          XMLTYPE;
          xsldata        XMLTYPE;
          xmldata        XMLTYPE;
          l_dir          VARCHAR2 (1000);
       BEGIN
          LOG (   'Start Processing file '
               || p_file_name
               || ' from zip '
               || p_insert_date
          IF p_dir IS NULL
          THEN
             SELECT directory_path
               INTO l_dir
               FROM all_directories
              WHERE directory_name = g_zip_file_dir;
          ELSE
             l_dir := p_dir;
          END IF;
          IF g_xsl_clob IS NULL
          THEN
             init_xsl_clob;
          END IF;
          com_polecat_xmldb_utils.set_load_date
                                      (TO_DATE (REPLACE (REPLACE (p_insert_date,
                                                         '.zip',
                                                'DD-MM-YYYY'
          LOG ('ITEM.Loaddate set : ' || com_polecat_xmldb_utils.get_load_date);
          xsldata := XMLTYPE.createxml (g_xsl_clob);
          LOG ('Read xsl file to clob');
          DBMS_LOB.OPEN (src_clob, DBMS_LOB.lob_readonly);
          DBMS_LOB.createtemporary (dest_clob, TRUE);
          DBMS_LOB.loadclobfromfile (dest_lob          => dest_clob,
                                     src_bfile         => src_clob,
                                     amount            => DBMS_LOB.getlength
                                                                         (src_clob),
                                     dest_offset       => dst_offset,
                                     src_offset        => src_offset,
                                     bfile_csid        => NLS_CHARSET_ID
                                                                       ('AL32UTF8'),
                                     lang_context      => lang_ctx,
                                     warning           => warning
          LOG ('Read xml file to clob');
          DBMS_LOB.CLOSE (src_clob);
          parser := xmlparser.newparser;
          dest_clob := REPLACE (dest_clob, g_blog_dtd_remove, '');
          LOG ('Parse xml ');
          xmlparser.parseclob (parser, dest_clob);
          DBMS_LOB.freetemporary (dest_clob);
          newsxml := xmlparser.getdocument (parser);
          xmlparser.freeparser (parser);
          titles := xmldom.getelementsbytagname (newsxml, 'item');
          LOG ('Load  blogs items to ITEM table. ');
          FOR j IN 1 .. xmldom.getlength (titles)
          LOOP
             curnode := xmldom.item (titles, j - 1);
             DBMS_LOB.freetemporary (l_temp_clob);
             DBMS_LOB.createtemporary (l_temp_clob, TRUE);
             LOG ('write node to temp clob ' || j);
             xmldom.writetoclob (curnode, l_temp_clob);                                              <-- Hanging Here
             LOG ('create xml type from clob ' || j);
             l_xml := XMLTYPE.createxml (l_temp_clob);
             LOG ('apply xsl transform to xml ' || j);
             xmldata := l_xml.transform (xsldata);
             LOG ('Insert to item table  ' || j);
             BEGIN
                INSERT INTO item
                     VALUES (xmldata);
             EXCEPTION
                WHEN OTHERS
                THEN
                   LOG ('Error::  ' || SQLERRM);
             END;
          END LOOP;
          xmldom.freedocument (newsxml);
          LOG (   'Finished Processing file '
               || p_file_name
               || ' from zip '
               || p_insert_date
       EXCEPTION
          WHEN OTHERS
          THEN
             LOG (SQLERRM);
       END;note variables starting with g_ are defined in package spec
    Cheers
    Ian
    Edited by: user3604054 on 01-Apr-2010 06:52
    Edited by: user3604054 on 01-Apr-2010 14:57
    Edited by: user3604054 on 01-Apr-2010 15:00
    Edited by: user3604054 on 01-Apr-2010 15:00
    Edited by: user3604054 on 01-Apr-2010 15:05
    Edited by: user3604054 on 01-Apr-2010 15:06

    2. Get around the xmldom.writetoclob procedure and create an xmltype from the xmldom.domnode (i tried to convert domnode -> domdocument -> xmltype, no joy) Which version of Oracle (4 digits)?
    Also look in the FAQ in the upper right for how to use the tag to wrap PL/SQL to retain formatting to make it easier for all to read.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Oracle 9i and xmltype, ora-03001

    I get this message: 'ora-03001 unimplemented feature' when i
    trying to create a table with this statement: create table
    purchaseorder(podocument sys.xmltype);
    -The user has the following roles:
    connect, resource, javauserpriv, query rewrite, create any
    directory.
    -And execute privilege on xmlparser and xmldom (granted by sys).
    -The init.ora file is included with query_rewrite_enabled=true,
    query_rewrite_integrity=trusted.
    What's wrong?

    Colleague, I had problem the same that its, also with the postagem of a message here in this forum. I have the successfully installed Oracle 9i EE, after two weeks of very work, in IBM to xServer 220, with SuSE 7.2 This error occurred due to the fact of incorrect parameters of the init.ora, as well as, through some definite parameters incorrectly, in that if it says respect the 0 variable of environment of the ORACLE. One remembers to modify parameter REMOTE_LOGIN... of EXCLUSIVE for NONE and of preference it comments this in its archive INIT.ORA. Of one looked at in check list of installation of the Oracle, as well as in the specific manual of pattern for its distribution for the correct definition of the parameters of its archive of pattern.

  • Load XLM into pl sql using xmldom

    Hi ,
    I have problems when I use xmldom to retrieve infotmation from xml to storethe information into a table. For the first xml , I can do it , for the second one I have problems ( I can't retrieve the values I need ) and I don't know why. Please don't reply me by providing links , I just would like to have an idea of what is going wrong with the second xml. Thanks in advance.
    It works fine with this one :
    <?xml version="1.0" encoding="windows-1252" ?>
    - <GraydonBeDialogue>
    <TransactionCode>RTB</TransactionCode>
    - <Table ClassTable="Country">
    - <TableEntry>
    <TableLanguage>N</TableLanguage>
    <TableCode>AD</TableCode>
    <TableValue>Andorra</TableValue>
    </TableEntry>
    - <TableEntry>
    <TableLanguage>N</TableLanguage>
    <TableCode>AE</TableCode>
    <TableValue>Verenigde Arabische Emiraten</TableValue>
    </TableEntry>
    - <TableEntry>
    <TableLanguage>N</TableLanguage>
    <TableCode>AF</TableCode>
    <TableValue>Afghanistan</TableValue>
    </TableEntry>
    - <TableEntry>
    <TableLanguage>N</TableLanguage>
    <TableCode>AG</TableCode>
    <TableValue>Antigua en Barbuda</TableValue>
    </TableEntry>
    But it does not work with this one :
    <?xml version="1.0" encoding="windows-1252" ?>
    - <GraydonBeDialogue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com Z:\PROGRAMMATIE\AS400\projecten\XML\GraydonBe\InfoReview\Review.xsd" xmlns="http://www.w3schools.com">
    <Transaction>PDT</Transaction>
    - <GraydonBeInformation>
    - <Default>
    <DateFormat>YYYYMMDD</DateFormat>
    <TimeFormat>HHMMSS</TimeFormat>
    <Currency>EUR</Currency>
    <CountryCode>BE</CountryCode>
    <DecimalSign>.</DecimalSign>
    </Default>
    - <Header>
    <Name>GRAYDON BELGIUM NV /SA</Name>
    <ContentGenerationDate>20050722</ContentGenerationDate>
    <ContentGenerationTime>101110</ContentGenerationTime>
    <Product>REV</Product>
    <ClientNumber>156</ClientNumber>
    </Header>
    - <Body>
    - <Msg48>
    - <MsgHeader>
    <MsgDate>20050712</MsgDate>
    <MsgCode Table="RevDsoMsg">48</MsgCode>
    - <Business>
    <BusinessNumber>0480316383</BusinessNumber>
    <Name>STANLEYBET BELGIQUE SA</Name>
    - <Address>
    <Street>PEGASUSLAAN 5</Street>
    <PostCode>1831</PostCode>
    <City>MACHELEN</City>
    </Address>
    </Business>
    </MsgHeader>
    <SinceDate Format="YYYYMM">200506</SinceDate>
    </Msg48>
    - <Msg123>
    - <MsgHeader>
    <MsgDate>20050711</MsgDate>
    <MsgCode Table="RevDsoMsg">123</MsgCode>
    - <Business>
    <BusinessNumber>0403157932</BusinessNumber>
    <Name>CELANESE NV</Name>
    - <Address>
    <Street>INDUSTRIEWEG 80</Street>
    <PostCode>3620</PostCode>
    <City>LANAKEN</City>
    </Address>
    </Business>
    </MsgHeader>
    - <PreviousCreditAssessement>
    <CreditAssessementAmount>10691000</CreditAssessementAmount>
    </PreviousCreditAssessement>
    - <NewCreditAssessement>
    <CreditAssessementAmount>9706000</CreditAssessementAmount>
    </NewCreditAssessement>
    </Msg123>
    Could you explain me what could be wrong ?
    I am using the same logic for both xml :
    declare
    bnb xmldom.domnodelist;
    l_node xmldom.domnode;
    l_doc xmldom.domdocument;
    begin
    parse_document (l_file_name, doc_in);
    bnb := selected_nodes (doc_in, '/GraydonBeDialogue/Table[@ClassTable="Review"]/TableEntry');
    FOR entry_index IN 0 .. xmldom.getlength (bnb) - 1
    LOOP
    l_node := xmldom.item (bnb, entry_index);
    TableLanguage := trim(xslprocessor.valueof (l_node, 'TableLanguage'));
    TableCode := trim(xslprocessor.valueof (l_node, 'TableCode'));
    TableValue := trim(xslprocessor.valueof (l_node, 'TableValue'));
    -- Treat the data
    .....

    Couple of friendly tips.
    When pasting XML, don't copy it directly from the browser's normal view as that usually inserts a "-" on some lines, which makes it invalid XML when you copy/paste. Either open the XML in something besides a browser or do a View Page Source (or similar) to copy the true XML.
    Use the tag to wrap XML and code to retain formatting as shown in the FAQ (under your sign-in name in the upper right).
    In your first sample XML, the root node is defined as
    <GraydonBeDialogue>
    and in the second it is defined as (ignoring attributes that don't matter to us now)
    <GraydonBeDialogue xmlns="http://www.w3schools.com">
    This means the second XML resides in a default namespace and so to access any/all nodes that reside in this namespace, you must provide that namespace to the extract method.
    For many Oracle based functions that take an Xpath as a parm, Oracle has the next parm defined as the namespace.  This allows you to pass in the namespace associated to the XML nodes.  With default namespaces, it does add a twist as you have to make up a namespace prefix for the Xpath/namespace declaration so that the engine knows the nodes reside in a namespace (be it default) instead of not residing in a namespace.  Here's a little something I wrote up on this
    http://anononxml.blogspot.com/2010/06/xml-parsing-with-default-namespaces-via.html
    I prefer now to use XMLType when parsing XML in PL/SQL as a bit more flexible/easier to code.
    Without seeing what you hid in
    selected_nodes
    it is hard to say exactly where your problem is but hopefully that gives you a start.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Problem due to xmldom.DOMDocument

    Hi,
    I have written a function where i have used xmldom in the matter as listed below :
    doc xmldom.DOMDocument;
    main_node xmldom.DOMNode;
    root_node xmldom.DOMNode;
    user_node xmldom.DOMNode;
    item_node xmldom.DOMNode;
    root_elmt xmldom.DOMElement;
    item_elmt xmldom.DOMElement;
    item_text xmldom.DOMText;
    abc clob;
    doc := xmldom.newDOMDocument;
    main_node := xmldom.makeNode(doc);
    root_elmt := xmldom.createElement(
    doc,
    'Menubar'
    root_node := xmldom.appendChild(
    main_node,
    xmldom.makeNode(root_elmt)
    like wise i am writing into Doc but i have to return evry root or node written using doc to calling environment so i need to read this doc and convert it xmltype so i as to read it but there is complilation error at the point
    abc :=doc
    and the error is PLS-00382: expression is of wrong type
    any suggestion how can i overcome it i can paste the whole code if needed.
    Regards
    Vikas Kumar

    Hello
    The error is coming as you are trying to put DOM Document in either clob or xmltype which are not of the same datatype as xmldom. In the post you have abc of clob type where as in the code you mailed it is xmltype.
    In first scenario i.e. if abc is clob you may have to write something similar to
    xmldom.writetoclob(doc,abc);
    In second Scenario i.e. if abc is xmltype
    DBMS_LOB.CreateTemporary(v_xml_clob, TRUE);
    xmldom.writetoclob(doc,v_xml_clob);
    abc := new xmltype(v_xml_clob);

  • INSERTION OF XML DATA INTO THE TABLE USING XMLDOM

    hello,
    i am using XMLDOM to insert the data into the table
    i am using different function of it.
    but i am facing the problem to retrive the the multiple entry.
    like in my example i have two entry of the ' po number '
    & i am using the function
    dbms_xmldom.item(l_nodelist, 0)
    i which i have to pass index no.
    & through this i am getting only single entry according to the index no.
    Example on which i am working is
    declare
    l_xml_data CLOB;
    l_xml_doc dbms_xmldom.domdocument;
    l_nodelist dbms_xmldom.DOMNodeList;
    l_node dbms_xmldom.domnode;
    l_xmltype XMLTYPE;
    l_po_num VARCHAR2(30);
    l_cust_ord VARCHAR2(30);
    l_item_code VARCHAR2(30);
    begin
    l_xml_data := '<?xml version="1.0" encoding="UTF-8"?>
    <!--DOCTYPE MobileInventoryResponse SYSTEM "MobileInventoryResponse.dtd"-->
    <MobileInventoryResponse>
         <message>
              <message-header>
                   <message-id>16244182</message-id>
                   <transaction-name>ship-advice</transaction-name>
                   <partner-name>cbeyond</partner-name>
                   <source-url>http://www.brightpoint.com</source-url>
                   <create-timestamp>20080826150709</create-timestamp>
                   <response-request>1</response-request>
              </message-header>
              <ship-advice>
                   <header>
                        <customer-id>297859</customer-id>
                        <shipment-information>
                             <ship-first-name>RA_13Aug_1</ship-first-name>
                             <ship-last-name>MIND</ship-last-name>
                             <ship-address1>test</ship-address1>
                             <ship-city>test</ship-city>
                             <ship-state>VA</ship-state>
                             <ship-post-code>22102-4931</ship-post-code>
                             <ship-country-code>US</ship-country-code>
    <ship-phone1>0040726335068</ship-phone1>
    <ship-email>[email protected]</ship-email>
    <ship-via>FX01</ship-via>
    <ship-request-date>20080826</ship-request-date>
    <ship-request-warehouse>CBY1</ship-request-warehouse>
    </shipment-information>
    <purchase-order-information>
    <purchase-order-number>380928</purchase-order-number>
    <purchase-order-number>380929</purchase-order-number> ----modi by Ananda Dubey
    <account-description/>
    <purchase-order-amount>0.0</purchase-order-amount>
    <currency-code>USD</currency-code>
    </purchase-order-information>
    <order-header>
    <customer-order-number>0002759</customer-order-number>
    <customer-order-date>20080826</customer-order-date>
    <order-sub-total>19.0</order-sub-total>
    <order-discount>0.0</order-discount>
    <order-tax1>0.0</order-tax1>
    <order-tax2>0.0</order-tax2>
    <order-tax3>0.0</order-tax3>
    <order-shipment-charge>18.0</order-shipment-charge>
    <order-total-net>0.0</order-total-net>
    <order-status>Completed</order-status>
    <order-type/>
    <brightpoint-order-number>35028788</brightpoint-order-number>
    <warehouse-id>CBY1</warehouse-id>
    <ship-date>20080826</ship-date>
    </order-header>
    </header>
    <detail>
    <line-item>
    <line-no>1</line-no>
    <item-code>SKU1</item-code>
    <universal-product-code>0</universal-product-code>
    <ship-quantity>1.0</ship-quantity>
    <unit-of-measure>EA</unit-of-measure>
    <serial-list>
    <serial-numbers>
    <esn>TIMI000013</esn>
    </serial-numbers>
    </serial-list>
    <line-status/>
    <base-price>0.0</base-price>
    <line-discount>0.0</line-discount>
    <line-tax1>0.0</line-tax1>
    <line-tax2>0.0</line-tax2>
    <line-tax3>0.0</line-tax3>
    <bill-of-lading>929406733828</bill-of-lading>
    <scac>FX01</scac>
    </line-item>
    </detail>
    </ship-advice>
    <transactionInfo>
                   <eventID>16244182</eventID>
              </transactionInfo>
         </message>
    </MobileInventoryResponse>';
    l_xml_doc := dbms_xmldom.newDomDocument(l_xml_data);
    -- Method 1 to get data
    l_nodelist := dbms_xmldom.getelementsbytagname(l_xml_doc, 'purchase-order-number');
    l_node := dbms_xmldom.item(l_nodelist, 0); -- gets first item from list
    l_po_num := dbms_xmldom.getnodevalue(dbms_xmldom.getfirstchild(l_node));
    dbms_output.put_line(l_po_num);
    l_nodelist := dbms_xslprocessor.selectnodes(dbms_xmldom.makenode(l_xml_doc),
    '/MobileInventoryResponse/message/ship-advice/detail/line-item/item-code');
    l_node := dbms_xmldom.item(l_nodelist, 0); -- gets first item from list
    l_item_code := dbms_xmldom.getnodevalue(dbms_xmldom.getfirstchild(l_node));
    dbms_output.put_line(l_item_code);
    l_xmltype := XMLTYPE(l_xml_data);
    l_cust_ord := l_xmltype.extract('/MobileInventoryResponse/message/ship-advice/header/order-header/customer-order-number/text()').getStringVal();
    dbms_output.put_line(l_cust_ord);
    dbms_xmldom.freeDocument(l_xml_doc);
    end;
    /

    In the following code
    l_nodelist := dbms_xmldom.getelementsbytagname(l_xml_doc, 'purchase-order-number');
    l_node := dbms_xmldom.item(l_nodelist, 0); -- gets first item from listYou need to understand what the second parm on the .item call does. See [dbms_xmldom.item|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_xmldom.htm#i1126138]
    The nodelist is a 0 based array of information and you are only requesting to pull the node info in the first array position. So to get the info in the second array position, you need to use ", 1)". You can also use .getLength and a loop to parse through everything in the node list.

  • Oracle and XMLType

    Hi,
    I have stored a instance of XMLDocument on my Oracle db.
    I have used XMLType object (oracle.xml.parser.v2) to take it value.
    XmlType Xml = XMLType.createXML(orset.getOPAQUE("Policy"));
    So, I cast value to create a XMLDOM document
    Document XmlDoc = (Document) Xml.getDOM();
    But when I try to access XMLDOM this value occured :
    An unexpected exception has been detected in native code outside the VM.
    Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0xF532F2E
    Function=qmxPrintXobToStreamWithPfx+0x2E
    Library=C:\oracle\ora92\bin\orageneric9.dll
    Current Java thread:
         at oracle.xdb.dom.XDBNode.toStringNative(Native Method)
         - locked <02A20FF0> (a oracle.xdb.dom.XDBElement)
         at oracle.xdb.dom.XDBNode.toString(XDBNode.java:510)
         at java.lang.String.valueOf(String.java:2177)
         at java.io.PrintStream.print(PrintStream.java:462)
         at firstimpl.FirstImpl.NodeRules(FirstImpl.java:338)
         at firstimpl.FirstImpl.NodeRegistration(FirstImpl.java:380)
         at firstimpl.FirstImpl.<init>(FirstImpl.java:127)
         at firstimpl.FirstImpl.main(FirstImpl.java:1307)
    Thanks in advance,
    Omar

    Looks like a bug in orageneric9.dll
    You should search Oracle's bug listings and patches.

  • Xmldom, xslprocessor package and namespace

    Hello,
    First as I'm a newbie, is there a complete documentation on XML DB for developpers in oracle.com ?
    Now my problem : I'm using in PLSQL xmldom, xslprocessor package with XPATH method to retrieve some information.
    I have tested the code and it works except when I have this in the XML file :
    xmlns="x-schema:OpenShipments.xdr"
    THIS IS THE CODE I USE ( xmldom, xslprocessor are encapsulated ):
    FUNCTION Extract_Info( p_file_path IN VARCHAR2 -- path of the file, sample : /u01/E11T/e11tappl/als/11.5.0/
    ,p_file_name IN VARCHAR2 -- name of the file : sample UPS_1.xml
              ,p_nodelist IN VARCHAR2 -- list of XML nodes such as '/OpenShipments/OpenShipment/Receiver'
              ,p_node_attribute IN VARCHAR2 -- the node or attribute to analyse, sample for UPS : AddressLine1
              ,p_position IN NUMBER -- if 1 the first value retrieved is given, if 2 the second, if 3 ....
              ,p_message OUT VARCHAR2 -- error message
              ,p_res OUT VARCHAR2 -- error code 'S' if success, 'E' if error
    RETURN VARCHAR2
    IS
    l_return VARCHAR2(2000);
    BEGIN
    DECLARE
    doc_out xmldom.domdocument;
    file_in VARCHAR2(150):=p_file_path || p_file_name; ---
    l_nodelist xmldom.domnodelist;
    l_node xmldom.domnode;
    l NUMBER;
    l_message VARCHAR2(2000):=NULL;
    l_res VARCHAR2(1):='S';
    BEGIN
    ALS_XML_PK.parse_document (file_in,doc_out);
    l_nodelist:=ALS_XML_PK.selected_nodes (doc_out,p_nodelist);
    l_node := xmldom.item (l_nodelist,p_position-1);
    l_return:=xslprocessor.valueof (l_node,p_node_attribute);
    -- to check number of nodes
    -- l:=xmldom.getlength(l_nodelist);
    --dbms_output.put_line('nombre de node ' || xmldom.getlength(l_nodelist));
    --dbms_output.put_line('valeur ' || NVL(l_return,'IS NULL !!'));
    EXCEPTION
    WHEN xmldom.index_size_err
    THEN
    l_res:='E';
         l_message:='INDEX SIZE error';
    --raise_application_error (-20120, 'INDEX SIZE error');
    WHEN xmldom.domstring_size_err
    THEN
    l_res:='E';
         l_message:='String SIZE error';
    --raise_application_error (-20120, 'String SIZE error');
    WHEN xmldom.hierarchy_request_err
    THEN
    l_res:='E';
         l_message:='Hierarchy request error';
    --raise_application_error (-20120,'Hierarchy request error');
    WHEN xmldom.wrong_document_err
    THEN
    l_res:='E';
         l_message:='Wrong doc error';
    --raise_application_error (-20120, 'Wrong doc error');
    WHEN xmldom.invalid_character_err
    THEN
    l_res:='E';
         l_message:='Invalid CHAR error';
    --raise_application_error (-20120, 'Invalid CHAR error');
    WHEN xmldom.no_data_allowed_err
    THEN
    l_res:='E';
         l_message:='Nod data allowed error';
    --raise_application_error (-20120,'Nod data allowed error');
    WHEN xmldom.no_modification_allowed_err
    THEN
    l_res:='E';
         l_message:='No MOD allowed error';
    --raise_application_error (-20120,'No MOD allowed error');
    WHEN xmldom.not_found_err
    THEN
    l_res:='E';
         l_message:='NOT FOUND error';
    --raise_application_error (-20120, 'NOT FOUND error');
    WHEN xmldom.not_supported_err
    THEN
    l_res:='E';
         l_message:='NOT supported error';
    --raise_application_error (-20120,'NOT supported error');
    WHEN xmldom.inuse_attribute_err
    THEN
    l_res:='E';
         l_message:='IN USE attr error';
    --raise_application_error (-20120, 'IN USE attr error');
    END;
    -- return value extracted
    RETURN l_return;
    END Extract_Info;
    ---> error is with namespace :
    ORA-20100: Error occurred while parsing: Permission denied
    Message was edited by:
    ROMEO_G

    SQL> set serveroutput on
    SQL> declare
      2    xmldoc1 xmltype := xmltype (
      3  '<OpenShipments>
      4    <OpenShipment ProcessStatus="TESTONS">
      5      <Receiver>
      6        <CompanyName>DUMMY</CompanyName>
      7        <ContactPerson>000000</ContactPerson>
      8        <AddressLine1>DUMM</AddressLine1>
      9        <AddressLine2>DUMDUM</AddressLine2>
    10        <AddressLine3/>
    11        <City>PROUT</City>
    12        <CountryCode>BE</CountryCode>
    13        <PostalCode>1111</PostalCode>
    14        <Residential>0</Residential>
    15        <CustomerIDNumber>0</CustomerIDNumber>
    16        <Phone>0</Phone>
    17        <TaxIDNumber>0</TaxIDNumber>
    18        <LocationID/>
    19        <UpsAccountNumber>0</UpsAccountNumber>
    20        <RecordOwner>0</RecordOwner>
    21      </Receiver>
    22      <Shipment>
    23        <ServiceLevel>1</ServiceLevel>
    24        <PackageType/>
    25        <NumberOfPackages>1</NumberOfPackages>
    26        <ShipmentActualWeight>1</ShipmentActualWeight>
    27        <DescriptionOfGoods/>
    28        <Reference1/>
    29        <Reference2/>
    30        <DocumentOnly>1</DocumentOnly>
    31        <GoodsNotInFreeCirculation>1</GoodsNotInFreeCirculation>
    32        <BillingOption>1</BillingOption>
    33        <DeclareValue>
    34          <Amount>1</Amount>
    35        </DeclareValue>
    36      </Shipment>
    37    </OpenShipment>
    38  </OpenShipments>');
    39
    40    xmldoc2 xmltype := xmltype (
    41  '<OpenShipments xmlns="x-schema:OpenShipments.xdr">
    42    <OpenShipment ProcessStatus="TESTONS">
    43      <Receiver>
    44        <CompanyName>DUMMY</CompanyName>
    45        <ContactPerson>000000</ContactPerson>
    46        <AddressLine1>DUMM</AddressLine1>
    47        <AddressLine2>DUMDUM</AddressLine2>
    48        <AddressLine3/>
    49        <City>PROUT</City>
    50        <CountryCode>BE</CountryCode>
    51        <PostalCode>1111</PostalCode>
    52        <Residential>0</Residential>
    53        <CustomerIDNumber>0</CustomerIDNumber>
    54        <Phone>0</Phone>
    55        <TaxIDNumber>0</TaxIDNumber>
    56        <LocationID/>
    57        <UpsAccountNumber>0</UpsAccountNumber>
    58        <RecordOwner>0</RecordOwner>
    59      </Receiver>
    60      <Shipment>
    61        <ServiceLevel>1</ServiceLevel>
    62        <PackageType/>
    63        <NumberOfPackages>1</NumberOfPackages>
    64        <ShipmentActualWeight>1</ShipmentActualWeight>
    65        <DescriptionOfGoods/>
    66        <Reference1/>
    67        <Reference2/>
    68        <DocumentOnly>1</DocumentOnly>
    69        <GoodsNotInFreeCirculation>1</GoodsNotInFreeCirculation>
    70        <BillingOption>1</BillingOption>
    71        <DeclareValue>
    72          <Amount>1</Amount>
    73        </DeclareValue>
    74      </Shipment>
    75    </OpenShipment>
    76  </OpenShipments>');
    77
    78    DOC DBMS_XMLDOM.DOMDOCUMENT;
    79    NL DBMS_XMLDOM.DOMNODELIST;
    80  begin
    81
    82    DOC := DBMS_XMLDOM.newDOMDocument(xmldoc1);
    83    NL  := DBMS_XSLPROCESSOR.selectNodes(dbms_xmldom.makeNode(DOC),'/OpenShipments/OpenShipment/Receiver');
    84    dbms_output.put_line('NodeList.length() = ' || DBMS_XMLDOM.GETLENGTH(NL));
    85
    86    DOC := DBMS_XMLDOM.newDOMDocument(xmldoc2);
    87    NL  := DBMS_XSLPROCESSOR.selectNodes(dbms_xmldom.makeNode(DOC),'/OpenShipments/OpenShipment/Receiver');
    88    dbms_output.put_line('NodeList.length() = ' || DBMS_XMLDOM.GETLENGTH(NL));
    89
    90    NL  := DBMS_XSLPROCESSOR.selectNodes(dbms_xmldom.makeNode(DOC),'/OpenShipments/OpenShipment/Receiver','xmlns="x-schema:OpenShipments.
    xdr"');
    91    dbms_output.put_line('NodeList.length() = ' || DBMS_XMLDOM.GETLENGTH(NL));
    92
    93  end;
    94
    95  /
    NodeList.length() = 1
    NodeList.length() = 0
    NodeList.length() = 1
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.12
    SQL>The doc does not show that SELECTNODES takes a third argument, which is the namespace prefix mappings for the document. However a describe of the package does show that there is a third agument. A doc bug has been filed.

  • XMLDOM.appendChild performance

    Hi All,
    I have a large xml (52,000 messages under the root element). There's about 5 elements under each Message element. Parsing each element takes about 2 minutes which is great. However, when I try to add two more elements under the message element using XMLDOM.appendChild , the execution time goes up to 11 minutes.
    DB Version: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit
    Any ideas on how to make it run faster?
    Is there an issue with XMLDOM.appendChild

    Hi,
    Any ideas on how to make it run faster?
    Is there an issue with XMLDOM.appendChildActually, there's an issue with the whole approach.
    Given your db version, you should stop using DOM and start using binary XMLType and related functionalities.
    Could you describe a little bit more what you want to do? A sample data with expected output would help.
    - What does "parsing" mean to you? Extracting XML data into variables or columns?
    - Do you want to add two more elements under each of the 52000 Messages?
    Here's a glimpse of what you can do :
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> create table tmp_xml of xmltype;
    Table created.Creating a sample document with 10000 messages...
    SQL> set timing on
    SQL> insert into tmp_xml
      2  select xmlelement("root",
      3           xmlagg(
      4             xmlelement("message",
      5               xmlforest(
      6                 'A'||to_char(level, 'fm09999') as "item1"
      7               , 'B'||to_char(level, 'fm09999') as "item2"
      8               , 'C'||to_char(level, 'fm09999') as "item3"
      9               , 'D'||to_char(level, 'fm09999') as "item4"
    10               , 'E'||to_char(level, 'fm09999') as "item5"
    11               )
    12             )
    13           )
    14         )
    15  from dual
    16  connect by level <= 10000 ;
    1 row created.
    Elapsed: 00:00:00.56
    SQL>Parsing into a relational structure...
    SQL> select x.*
      2  from tmp_xml t
      3     , xmltable(
      4         '/root/message'
      5         passing t.object_value
      6         columns item1 varchar2(6) path 'item1'
      7               , item2 varchar2(6) path 'item2'
      8               , item3 varchar2(6) path 'item3'
      9               , item4 varchar2(6) path 'item4'
    10               , item5 varchar2(6) path 'item5'
    11       ) x
    12  where rownum <= 10 ;
    ITEM1  ITEM2  ITEM3  ITEM4  ITEM5
    A00001 B00001 C00001 D00001 E00001
    A00002 B00002 C00002 D00002 E00002
    A00003 B00003 C00003 D00003 E00003
    A00004 B00004 C00004 D00004 E00004
    A00005 B00005 C00005 D00005 E00005
    A00006 B00006 C00006 D00006 E00006
    A00007 B00007 C00007 D00007 E00007
    A00008 B00008 C00008 D00008 E00008
    A00009 B00009 C00009 D00009 E00009
    A00010 B00010 C00010 D00010 E00010
    10 rows selected.
    Elapsed: 00:00:00.37
    SQL>Appending two more children to each message using XQuery Update (11.2.0.3 only) :
    SQL> update tmp_xml t
      2  set t.object_value =
      3         xmlquery(
      4           'copy $d := .
      5            modify (
      6              for $i in $d/root/message
      7              return insert node $e into $i
      8            )
      9            return $d'
    10          passing t.object_value
    11               ,  xmlconcat(
    12                    xmlelement("item6")
    13                  , xmlelement("item7")
    14                  ) as "e"
    15          returning content
    16         )
    17  ;
    1 row updated.
    Elapsed: 00:00:04.25
    SQL>
    SQL> set long 500
    SQL> set pages 100
    SQL> select object_value from tmp_xml ;
    OBJECT_VALUE
    <root>
      <message>
        <item1>A00001</item1>
        <item2>B00001</item2>
        <item3>C00001</item3>
        <item4>D00001</item4>
        <item5>E00001</item5>
        <item6/>
        <item7/>
      </message>
      <message>
        <item1>A00002</item1>
        <item2>B00002</item2>
        <item3>C00002</item3>
        <item4>D00002</item4>
        <item5>E00002</item5>
        <item6/>
        <item7/>
      </message>
      <message>
        <item1>A00003</item1>
        <item2>B00003</item2>
        <item3>C00003</item3>
        <item4>D00003</item4>
        <item5>E000
    Elapsed: 00:00:00.14Edited by: odie_63 on 7 janv. 2013 00:12

  • XMLDOM and CDATA

    Guru's,
    I have a requirement using PL/SQL whereby I need to store more that 32K bytes of HTML in an XML Element. Since the content is HTML, it seems to me that I have to use the CDATA method of XMLDOM
    (for example item_node := xmldom.appendChild(item_node, xmldom.makeNode(xmldom.createCDATASection(doc, p_bodycopy)));)
    My issue is that the createCDATASection can only handle a VARCHAR2, and I require it to handle (at most) 64K of information.
    I can use the AppendData procedure w/ Character data, but that creates decode,translation and transformation issues.
    Is there any light at the end of this tunnel? or should I punt.
    The following works very well for everything <= 32K
    item_elmt := xmldom.createElement(doc, 'BodyCopy');
    item_node := xmldom.appendChild(root_node, xmldom.makeNode(item_elmt));
    item_node := xmldom.appendChild(item_node, xmldom.makeNode(xmldom.createCDATASection(doc, p_bodycopy)));
    I am looking for a solution for content >32K
    Any insight is much appreciated.
    -Scot

    Hi Scot. Unfortunately most of the xml packages and functions are brain dead when it comes to handling large data. Most are implicitly tied to varchar limits and lob limitations in PL/SQL.
    To get a CDATA element exactly as you describe, I think you need to resort to building it up from 1st principles using lob methods.
    e.g.
    declare
    v_lob clob;
    v_lob_temp clob;
    begin
    v_lob := '<FamilyHistory><![CDATA[';
    select x.bigdata into v_lob_temp from x1 x where x.item='mysample';
    DBMS_LOB.APPEND(v_lob, v_lob_temp );
    DBMS_LOB.APPEND(v_lob, ']]></FamilyHistory>');
    insert into x2 values('mysample',v_lob);
    end;
    There is an approach using xmltype views based on object types, but these will implicitly xml encode your clob rather than quote it as CDATA (and I don't know a way to prevent this).
    e.g.
    CREATE TABLE x1 (item varchar(25) primary key, bigdata clob);
    -- (insert a very large record)
    CREATE OR REPLACE TYPE x1_t AS OBJECT
    (Holder varchar(25),BookData CLOB);
    CREATE OR REPLACE VIEW vx1 OF XMLTYPE
    WITH OBJECT ID (ExtractValue(sys_nc_rowinfo$, '/ROW/HOLDER')) AS
    SELECT sys_XMLGen(x1_t(x.item, x.bigdata)) from x1 x;
    Here's a sample entry:
    SELECT
         extractvalue(x.SYS_NC_ROWINFO$,'/ROW/HOLDER') as holder
         ,'xml_length: ' || dbms_lob.getlength(x.SYS_NC_ROWINFO$.getclobval()) as xml_length
    FROM vx1 x;
    HOLDER XML_LENGTH
    mysample xml_length: 324198
    Note sql*plus has a problem querying this:
    SQL> select * from vx1;
    ERROR:
    OCI-31167: XML nodes over 64K in size cannot be inserted
    Unless we just go for the clob. In this example the "BOOKDATA" is pure unencoded XML in table X1, but automatically encoded in the xmltype view vx1:
    SQL> set long 200
    SQL> select (SYS_NC_ROWINFO$).GETCLOBVAL() from vx1;
    (SYS_NC_ROWINFO$).GETCLOBVAL()
    &lt;?xml version=&quot;1.0&quot;?&gt;
    &lt;ROW&gt;
    &lt;HOLDER&gt;mysample&lt;/HOLDER&gt;
    &lt;BOOKDATA&gt;&amp;lt;books&amp;gt;
    &amp;lt;book id=&amp;quot;1&amp;quot;&amp;gt;
    &amp;lt;title&amp;gt;the book 1 title&amp;lt;/title&amp;gt;
    &amp;lt;/book&amp;gt;
    &amp;lt;book id=&amp;quot;2&amp;qu

  • XMLType - add new node (simple question?)

    Help me, please. I've spent much time on trying resolve this problem with no result... Give sample code please.
    The problem is:
    declare
    vxml XMLType;
    begin
    vxml := XMLType('<A><B><C></C></B></A>');
    end;
    What I have to do in "[...]" to add new child-node to <C> node?
    As a result I whant vxml: '<A><B><C><new></new></C></B></A>'.
    And please:
    - don;t say about updateXML because it works only in SQL-DML
    - if You think it necessity to use dbms_xmldom, let me show how (I tried to use xmldom in many ways)
    Thank you in advance

    Please post this message at:
    Forums Home » Oracle Technology Network (OTN) » Products » Database » XML DB

  • XMLDOM not found

    HI,
    I am using oracle 10g. I want to parse an XMLType and retreive the data. I want to use the PL/SQL DOM API for this. I have written a function but its giving me an error the xmldom needs to be declared.
    CREATE OR REPLACE FUNCTION getDOMNode(EntitlementRule IN CLOB) RETURN xmldom.domnode IS
    -- Declare the local variables
    xmldoc CLOB;
    myParser xmlparser.Parser;
    indomdoc xmldom.domdocument;
    outdomdoct xmldom.domdocumenttype;
    outnode xmldom.domnode;
    BEGIN
    -- Get the XML document using the getXML() function defined in the database
    xmldoc := EntitlementRule;
    -- Get the new xml parser instance
    myParser := xmlparser.newParser;
    -- Parse the XML document
    xmlparser.parseClob(myParser, xmldoc);
    -- Get the XML's DOM document
    indomdoc := xmlparser.getDocument(myParser);
    -- Apply stylesheet to DOM document
    outnode := xmldom.makenode(indomdoc);
    -- Return the transformed output
    return(outnode);
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error(-20103, 'Exception occurred in getPLSAccountsHTML
    Function :'||SQLERRM);
    END getDOMNode;
    Errors for FUNCTION GETDOMNODE:
    LINE/COL ERROR
    0/0 PL/SQL: Compilation unit analysis terminated
    1/53 PLS-00201: identifier 'XMLDOM.DOMNODE' must be declared
    I was not logged in as XDB user. i thought this might be the problem. So logged in as sys and tried to grant permissions on XMLDOM packages but its giving me
    grant execute on XMLDOM to public;
    grant execute on XMLDOM to public
    ERROR at line 1:
    ORA-04042: procedure, function, package, or package body does not exist
    This means XMLDOM itself is not found....
    Please Help!!!!!!!!!!!!!!!

    Hi,
    If XML DB is installed can be verified through dba_registry. so when i do a select comp_name "Component" from dba_registry; i am getting
    Component
    Oracle Workspace Manager
    Oracle Database Catalog Views
    Oracle Database Packages and Types
    JServer JAVA Virtual Machine
    Oracle XDK
    This means that XDK is installed right??
    I was checking the link http://www.adp-gmbh.ch/ora/xml_db/install.html.
    If XDK is installed then cause of my problem may be something else...!!!
    Thanks
    Swetha

  • Saving xmldom.DOMDocument to a file

    Hi all!
    I have a problen saving an XML file generated from a SQL sentence in my Oracle 9i Database when the file is higer than 32K bytes.
    To save file i use UTL_FILE library and i have found that there is the problem.
    The code i use is the following:
    CREATE OR REPLACE PROCEDURE SIGADMIN.PRUEBA_CAUC0004_EXT AUTHID CURRENT_USER IS
    xml clob;
    vxml varchar2(100);
    xfile utl_file.file_type;
    doc xmldom.DOMDocument;
    BEGIN
    --Inicializamos el CLOB
    DBMS_LOB.CreateTemporary(xml,TRUE);
    --Pasar el DOM document a CLOB
    xmldom.writeToClob(doc,xml);
    xfile := utl_file.fopen('TEMP_DIR','PRUEBA_CAUC0004.xml','w');
    WHILE (pos < len) LOOP
    vxml := dbms_lob.substr(xml,100,pos);
    utl_file.put(xfile,vxml);
    pos := pos+100;
    END LOOP
    --Liberamos los recursos
    xmldom.freeDocument(doc);
    utl_file.fclose(xfile);
    ..

    What about
    clear screen
    connect bfile/bfile
    set termout on
    set feed on
    set lines 40
    set long 10000000
    set serveroutput on
    set echo on
    clear screen
    -- Using dbms_xslprocessor.clob2file
    drop directory STORE;
    CREATE directory store AS 'C:\TEMP';
    declare
    rc sys_refcursor;
    BEGIN
       open rc FOR
         SELECT * FROM
         ( SELECT rownum FROM dual connect BY level < 25 );
    dbms_xslprocessor.clob2file( xmltype( rc ).getclobval( ) , 'STORE','anton.xml');
    END;
    SELECT extract((XMLTYPE(bfilename('XMLSTORE','anton.xml'),NLS_CHARSET_ID('AL32UTF8'))),'*') AS "XML"
    from   dual;
    pause
    clear screen
    -- Using DBMS_XMLDOM.WRITETOFILE
    declare
         rc sys_refcursor;
         doc DBMS_XMLDOM.DOMDocument;
    begin
       open rc for
          select * from
            ( select rownum from dual connect by level < 25 );
          doc := DBMS_XMLDOM.NewDOMDocument(xmltype( rc ));
          DBMS_XMLDOM.WRITETOFILE(doc, 'STORE/marco.xml');
    end;
    SELECT extract((XMLTYPE(bfilename('XMLSTORE','marco.xml'),NLS_CHARSET_ID('AL32UTF8'))),'*') AS "XML"
    from   dual;

Maybe you are looking for

  • Open File Dialog appears TWICE when using servlet to download an attachment

    Hi, This is KILLING me!!! Please HELP..... I am using a servlet to download an xml file, which I build on the fly based on user interaction. The open file dialog appears nicely and I hit open. The dialog pops up again immediately and I have to click

  • No photo names in Web Gallery

    I just uploaded a web gallery (password protected) and after going to the trouble of putting names on all the photos in iPhoto (prior to the upload) was disappointed to see none in my corresponding web gallery. What gives?

  • What will happen when my Apple Care expire? Can I get another one?

    I just go my MBP 17" 6 months ago and I already had some quiet serious issue with that machine (motherboard replacement). I have also Apple Care. I wish to keep this machine as long as it is possible (5 years or so) and my question is can I buy anoth

  • Enhanced Receiver determination - Fatal Error.

    Hi All, We are using Enhanced Receiver Determination. We are getting Fatal error in SXMB_MONI though our Intarface mapping is working correctly but when tried testing from runtime work bench we are getting error. The error message shows SAP:Code area

  • Smart forms. How to setup logic for standard text usage.

    Hi All! Could you advise please is there a way, except abap programming, to setup in smart forms that different standard texts values (tcode so10) to be used based on different selected parameters (e.g. customers, vendors etc... ). e.g. For picking l