Currently I have table which stores xml in XMLType column which internally stores XML in BasicFile Clob,I have to migrate the XML data to store XMLType column which stores XML in secure file Binary XML. I have tried using examples given in link
https://community.oracle.com/thread/2396094?tstart=0 It works for normal XML which have no xsd/namespace reference but fails if we convert xml without namespace. Please suggest the solution.
Belows are DDL and error:
CREATE TABLE clob_table (x SYS.XMLTYPE,y VARCHAR2(30)) XMLTYPE x STORE AS BASICFILE CLOB;
CREATE TABLE binaryxml_table (x XMLTYPE,y VARCHAR2(30)) XMLTYPE x STORE AS BINARY XML;
Clob table has below xml in xmltype column
<?xml version="1.0"?>
<HwInt:Request>
<HwInt:Handle>
<HwInt:RequestD>
<HwInt:Ref>7Z</HwInt:Ref>
</HwInt:RequestD>
</HwInt:Handle></HwInt:Request>
When i run below insert query
insert into binaryxml_table (x,y)select x,y from clob_table;
it gives belows error
ORA-31061: XDB error: XML event error
ORA-19202: Error occurred in XML processing
In line 2 of orastream:
LPX-00234: namespace prefix "HwInt" is not declared
Is there any way we can ignore the namspace check while moving data ?
I'm struggling to understand how you inserted the XML into your clob table in the first place. Passing the document without a namespace to XMLType fails!
CREATE TABLE clob_table (x SYS.XMLTYPE,y VARCHAR2(30)) XMLTYPE x STORE AS BASICFILE CLOB;
CREATE TABLE binaryxml_table (x XMLTYPE,y VARCHAR2(30)) XMLTYPE x STORE AS BINARY XML;
insert into clob_table values (xmltype(
'<?xml version="1.0"?>
<HwInt:Request>
<HwInt:Handle>
<HwInt:RequestD>
<HwInt:Ref>7Z</HwInt:Ref>
</HwInt:RequestD>
</HwInt:Handle></HwInt:Request>'), 'stuff');
SQL Error: ORA-31011: XML parsing failed
Unless you cheat and tell Oracle the document is well formed when it isn't:
insert into clob_table values (xmlparse(document
'<?xml version="1.0"?>
<HwInt:Request>
<HwInt:Handle>
<HwInt:RequestD>
<HwInt:Ref>7Z</HwInt:Ref>
</HwInt:RequestD>
</HwInt:Handle></HwInt:Request>' wellformed), 'stuff');
I think your best bet it to convert it back to a string. Then change it to either remove the HwInt namespaces or define it!
insert into binaryxml_table (x,y)
select xmltype(replace(xmlserialize(content x), 'HwInt:')),y
from clob_table;
select * from binaryxml_table;
X
------------------------------
Y
------------------------------
<?xml version="1.0"?>
<Request>
<Handle>
<RequestD>
<Ref>7Z</Ref>
</RequestD>
</Handle>
</Request>
stuff