tags:

views:

2146

answers:

2

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"&gt;

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

A: 

If I remember correctly, that error message is given when XDB (Oracle's XML DataBase package) is not properly installed. Have the DBA check this out.

Adam Hawkes
+1  A: 

Once you get past the install issues, there are challenges in some Oracle versions when the schemas get big, particularly when you have schemas that include other schemas. I know we had that issue in 9.2, not sure about 10.2 or 11.

For small schemas like your example, though, it should just work.

Jim Hudson