Link to home
Start Free TrialLog in
Avatar of Johann1
Johann1

asked on

How to add namespace information when using the XMLtype constructor and passing over XML string data?

Please let me add the following question...

I tried the solution for and it's looking good, but as I try to insert the contents of the nodeBuffer into an XMLtype table, oracle db complains about the following "ORA-30937" and "ORA-06512".
The reason seem to be the missing namespace information.

  xmlvar  XMLtype;
  nodebuffer clob;
...
  xmlvar := XMLType(nodebuffer);
   insert into C_AL2 values (xmlvar);

When I artificially edit my code and insert this information by hand, the code works.
nodebuffer := '<C  xmlns="http://www.xxx.com/ABC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">...</C>

Has anybody got an idea?
   
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

For you to be able to cast a CLOB as an XMLTYPE, it needs to be valid XML.

If you have something like <a><b:c>Hello</b:c></a> and don't have the namespace declared, it's not valid XML.

If you can't control how you build the CLOB then I think you'll need to do a REPLACE to add the namespace.

If you can provide a little more detail about the larger picture, I might be able to suggest alternatives.
Avatar of Johann1

ASKER

Thank you for your comments. I will give you some more details. So, this is my context:

The big task is to get XML data of a give schema into XMLtype tables inside the oracle database.
In order to achieve this, I created an auxiliary XMLtype table (as I just own the 10g database, I cannot use the binary XML type). Now, I insert one full xml file content into the auxiliary table.
Next step is to process the content of this single record inside the aux table in order to distribute it into the 'productive' xmltype tables. All xmltype tables, mentioned so far, are using the same xml schema S1. The source XML file (inserted into the aux table) uses an aggregating XML type from S1 containing sub elements that use other XML types from S1. For each of these sub elements there is a 'productive' XMLtype table inside the database, So, I read  one record from the aux table (one xml element) and want to distribute its subelements into the XMLtables of the respective XML types.
Here is the sequence...

1. create a DBMS_XMLparser and set a basedirectory in which the source xml file is copied.
2. parse the xml file.
3. get the domdocument form the parser.
4. get the uppermost (and also single) element (root node) using getElementsbytagname.
5. get the childnodes and store them in a domnodelist.
6. loop the domnodelist.
6a. check the nodename and compare it to one of the expected tagnames.
6b. createclob and write the node-xml into the buffer
     DBMS_LOB.CREATETEMPORARY(nodebuffer, TRUE);
     DBMS_XMLDOM.Writetoclob(node, nodebuffer);
6c. call a XMLtype constructor
      xmlvar  XMLtype;
       ...          
      xmlvar := XMLType(nodebuffer);
6d insert the XMLtype into the appropriate productive XMLtype table
      insert into p1table values (xmlvar);

During the last step, oracle tells me that about ORA-30937 and ORA-06512
If I add the namespace artificially in my code by hardcode-overwriting the buffer contents using an example string the insert works and no error message will occur.

So, that's why I ask about a solution to tell the xmltype constructor to insert the namespace information into the xml string I pass to it.

Are these descriptions clear enough? If not, please let me know. Thank you.

ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Johann1

ASKER

Thank you for that. Based on your previous comment I played around using DBMS_LOB functionality and managed to disassemble and reassemble the xml string theregy adding a namespace-substring. As I always have a constant namespace this solution will work, although I hoped there would be a more elegant solution ;-) . But I think that's fine for the moment. ...as the next problem has already shown up, as usual ;-)

Thank you very much, slightwv!