Note that there are some explanatory texts on larger screens.

plurals
  1. POValidating XML files against schema in Oracle PL/SQL
    text
    copied!<p>I have a requirement to validate an incoming file against an XSD. Both will be on the server file system.<br /></p> <p>I've looked at <code>dbms_xmlschema</code>, but have had issues getting it to work.</p> <p>Could it be easier to do it with some Java?<br />What's the simplest class I could put in the database?</p> <p>Here's a simple example:</p> <pre><code>DECLARE v_schema_url VARCHAR2(200) := 'http://www.example.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 =&gt; v_schema_url, schemaDoc =&gt; ' &lt;xs:schema targetNamespace="http://www.example.com" xmlns:ns="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="3.0"&gt; &lt;xs:element name="something" type="xs:string"/&gt; &lt;/xs:schema&gt;', local =&gt; TRUE); v_xml := XMLTYPE.createxml('&lt;something xmlns="http://www.xx.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/schema.xsd"&gt; data &lt;/something&gt;'); IF v_xml.isschemavalid(v_schema_url) = 1 THEN dbms_output.put_line('valid'); ELSE dbms_output.put_line('not valid'); END IF; END; </code></pre> <p>This generates the following error:</p> <pre><code>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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload