One of the new things in 11g is the possibility to set the method of how to enforce the validation / encoding of your XML document, straight away via embedding these options in your binary XML storage structure. It is just a small entry in the manual, but I think an important one. That’s why I wrote this small post, to emphasize this.
These extra options can be enabled during the creation of your binary XMLType table / column(s).
You have the option to use:
Validation via an XML Schema(s)
- ALLOW ANYSCHEMA
Encoding via an XML Schema
- ALLOW NONSCHEMA
- DISALLOW NONSCHEMA
You are allowed to mix these options. Currently even a little bit to much. XMLSCHEMA and the ALLOW ANYSCHEMA will be / should be mutually exclusive (and should be treated as such). Keep this in mind if you are using binary storage validation and encoding while using binary XML storage options.
How can you use them?
- XMLSCHEMA: Allows you to validate your XML instance against only one XSD, XML Schema.
- ALLOW ANYSCHEMA: Allows you to validate your XML instance against one or more XML Schemata.
Encoding based on XML Schema
- ALLOW NONSCHEMA: Gives you the option to allow encoding without using the referenced XML schema(ta).
- DISALLOW NONSCHEMA: Gives you the option to force encoding with using the referenced XML schema(ta).
So, for example, you are allowed to use XMLSCHEMA and ALLOW NONSCHEMA options in your create table of XMLType statement.
SQL> create table "XML_XSD_VAL01" of XMLTYPE 2 XMLTYPE STORE AS BASICFILE BINARY XML 3 XMLSCHEMA "http://www.myserver.com/root.xsd" 4 ELEMENT "ROOT" 5 ALLOW NONSCHEMA; Table created.
The shown XMLType table “will encode all XML schema-based documents using an encoding based on the referenced XML schema” called “root.xsd”, but it will also, as mentioned in the XMLDB Developers Guide, “encode all non-schema-based documents using the non-schema-based encoding“.
So my preference would be more like:
SQL> create table "XML_XSD_VAL01" of XMLTYPE 2 XMLTYPE STORE AS BASICFILE BINARY XML 3 XMLSCHEMA "http://www.myserver.com/root.xsd" 4 ELEMENT "ROOT" 5 DISALLOW NONSCHEMA; Table created.
The table enforces now validation based on the XML Schema registered (http://www.myserver.com/root.xsd) and encodes the binary data also on the “root.xsd” XML Schema. By the way…the schema must be registered for “binary use”.
How this can be achieved can be found on posts on this site (see the “howto” section) and/or (always a good idea) see the XMLDB Developers Guide or the good examples on the OTN XMLDB forum (and I hope I have my part in them).