Schema Validation Incorrect When Loading An XML Document That Is Invalid
(Doc ID 2496213.1)
Last updated on APRIL 17, 2023
Applies to:
Oracle Database - Enterprise Edition - Version 12.1.0.2 and laterInformation in this document applies to any platform.
Symptoms
XML Schema validation is incorrect when loading an XML document
example:
grant dba,resource,connect,create session,xdbadmin to scott;
conn scott/tiger
create or replace directory XSDDIR as '<path for xsd files>';
create or replace directory XMLDIR as '<path for xml files>';
grant read on directory XSDDIR to public ;
grant read on directory XMLDIR to public ;
create or replace function getXSDDocument(filename varchar2) return clob authid current_user is
xbfile bfile;
xclob clob;
destination_offset INTEGER := 1;
source_offset INTEGER := 1;
language_context INTEGER := DBMS_LOB.default_lang_ctx;
warning_message INTEGER;
begin
xbfile := bfilename('XSDDIR', filename);
dbms_lob.open(xbfile);
dbms_lob.createtemporary(xclob, TRUE, dbms_lob.session);
DBMS_LOB.LOADCLOBFROMFILE(xclob,
xbfile,
dbms_lob.getlength(xbfile),
destination_offset,
source_offset,
NLS_CHARSET_ID('UTF8'),
language_context,
warning_message);
dbms_lob.close(xbfile);
return xclob;
end;
/
create or replace function getXMLDocument(filename varchar2) return clob authid current_user is
xbfile bfile;
xclob clob;
destination_offset INTEGER := 1;
source_offset INTEGER := 1;
language_context INTEGER := DBMS_LOB.default_lang_ctx;
warning_message INTEGER;
begin
xbfile := bfilename('XMLDIR', filename);
dbms_lob.open(xbfile);
dbms_lob.createtemporary(xclob, TRUE, dbms_lob.session);
DBMS_LOB.LOADCLOBFROMFILE(xclob,
xbfile,
dbms_lob.getlength(xbfile),
destination_offset,
source_offset,
NLS_CHARSET_ID('UTF8'),
language_context,
warning_message);
dbms_lob.close(xbfile);
return xclob;
end;
/
declare
bret boolean;
begin
--bret := dbms_xdb.CreateFolder('/home');
bret := dbms_xdb.CreateFolder('/home/oracle');
bret := dbms_xdb.CreateFolder('/home/oracle/ris');
bret := dbms_xdb.CreateFolder('/home/oracle/ris/xsd');
bret := dbms_xdb.CreateFolder('/home/oracle/ris/xml');
end;
/
BEGIN
--dbms_xmlschema.deleteSchema(schemaURL => 'RGW.xsd',delete_option =>dbms_xmlschema.DELETE_CASCADE_FORCE ) ;
DBMS_XMLSCHEMA.registerSchema('RGW.xsd',getXSDDocument('RGW.xsd'));
END;
/
select count(*) from RIS_ORDERS;
COUNT(*)
----------
0
INSERT INTO ris_orders
VALUES (XMLType(bfilename('XMLDIR', 'RGW_Valid.xml'), nls_charset_id('AL32UTF8')));
INSERT INTO ris_orders
VALUES (XMLType(bfilename('XMLDIR', 'RGW_Invalid.xml'), nls_charset_id('AL32UTF8')));
INSERT INTO ris_orders
VALUES (XMLType(bfilename('XMLDIR', 'RGW_Invalid2.xml'), nls_charset_id('AL32UTF8')));
--all 3 rows insert without error
commit;
Changes
Cause
To view full details, sign in with your My Oracle Support account. |
|
Don't have a My Oracle Support account? Click to get started! |
In this Document
Symptoms |
Changes |
Cause |
Solution |