I have a requirement to validate an incoming file against an XSD. Both will be on the server file system.
I've looked at dbms_xmlschema, but have had issues getting it to work.
Could it be easier to do it with some Java? What's the simplest class I could put in the database?
Here's a simple example:
DECLARE
v_schema_url VARCHAR2(200) := 'http://www.xxx.com/schema.xsd';
v_blob bLOB;
v_clob CLOB;
v_xml XMLTYPE;
BEGIN
begin
dbms_xmlschema.deleteschema(v_schema_url);
exception when others then
null;
end;
dbms_xmlschema.registerSchema(schemaURL => v_schema_url,
schemaDoc => '
<xs:schema targetNamespace="http://www.xxx.com"
xmlns:ns="http://www.xxx.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified" version="3.0">
<xs:element name="something" type="xs:string"/>
</xs:schema>',
local => TRUE);
v_xml := XMLTYPE.createxml('<something xmlns="http://www.xx.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xxx.com/schema.xsd">
data
</something>');
IF v_xml.isschemavalid(v_schema_url) = 1 THEN
dbms_output.put_line('valid');
ELSE
dbms_output.put_line('not valid');
END IF;
END;
This gets an error:
ORA-01031: insufficient privileges ORA-06512: at "XDB.DBMS_XDBZ0", line 275 ORA-06512: at "XDB.DBMS_XDBZ", line 7 ORA-06512: at line 1 ORA-06512: at "XDB.DBMS_XMLSCHEMA_INT", line 3 ORA-06512: at "XDB.DBMS_XMLSCHEMA", line 14 ORA-06512: at line 12