This discussion is archived
4 Replies Latest reply: Aug 24, 2006 6:04 PM by mdrake RSS

How does XML DB handle XML Schema Validation ?

mdrake Expert
Currently Being Moderated
In order to validate an XML document against an XML Schema using Oracle XML DB the XML Schema must first be registered with XML DB using the method registerSchema provided by the package DBMS_XMLSCHEMA.

XDB provides two types of schema validation, 'Lax' Validation and 'Strict' Validation.

'Lax' validation takes place whenever a schema based document is converted from it's textual representation into the XML DB internal object model. Errors caught by this validation will be prefixed with 'ORA'.

'Stict' validation takes place when the XMLType methods schemaValidate() or isSchemaValid() are invoked.

The schemaValidate() method throws an exception with an error message indicating what is wrong it encounteres an invalid document. The error message associated with the exception will be prefixed with LSX.

The isSchemaValid() method returns true or false, depending on whether or not the document is valid. It cannot return any information about why the document is invalid.

The reason for having both the Lax and Strict validation models is that Strict validation is much more expensive in terms of CPU and memory usage than Lax validation.
  • 1. Re: How does XML DB handle XML Schema Validation ?
    mdrake Expert
    Currently Being Moderated
    The purpose of Lax validation is to ensure that the contents of teh XML document can be persisted successfully using the internal object model. Lax validation will catch the following kinds of error

    Documents that contain nodes (elements or attributes) which are not present in the XML schema,

    Invalid values for nodes that are defined as enumerations.

    Invalid values for date and numeric nodes

    Too many occurrences of repeating elements which a maxOccurs value of than unbounded.

    Lax validation will not catch errors like missing mandatory elements or attribute or too few occurences of repeating elements. In order to catch these errors a Strict Validation is required.
  • 2. Re: How does XML DB handle XML Schema Validation ?
    mdrake Expert
    Currently Being Moderated
    To force strict validation on insert or update of documents stored in a schema based XMLType table or column invoke schemaValidate() from a before insert or update trigger on table.
  • 3. Why do I get anORA-19030 when invoking schemaValidate() ?
    mdrake Expert
    Currently Being Moderated
    Here are some examples of what is caught by Lax validation (ORA errors) and what is only caught by Strict validation (LSX errors).
    SQL> begin
      2     dbms_xmlschema.registerSchema('test',xmltype(
      3  '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.co
    eFormDefault="unqualified">
      4     <xs:complexType name="RootType">
      5             <xs:sequence>
      6                     <xs:element name="Mandatory"/>
      7                     <xs:element name="Enumeration">
      8                             <xs:simpleType>
      9                                     <xs:restriction base="xs:string">
     10                                             <xs:enumeration value="A"/>
     11                                             <xs:enumeration value="B"/>
     12                                             <xs:enumeration value="C"/>
     13                                     </xs:restriction>
     14                             </xs:simpleType>
     15                     </xs:element>
     16                     <xs:element name="MinLength">
     17                             <xs:simpleType>
     18                                     <xs:restriction base="xs:string">
     19                                             <xs:minLength value="4"/>
     20                                             <xs:maxLength value="20"/>
     21                                     </xs:restriction>
     22                             </xs:simpleType>
     23                     </xs:element>
     24                     <xs:element name="MaxLength">
     25                             <xs:simpleType>
     26                                     <xs:restriction base="xs:string">
     27                                             <xs:minLength value="1"/>
     28                                             <xs:maxLength value="4"/>
     29                                     </xs:restriction>
     30                             </xs:simpleType>
     31                     </xs:element>
     32                     <xs:element name="MaxOccurs" type="xs:string" maxOccurs="2"/>
     33                     <xs:element name="MinOccurs" minOccurs="2" maxOccurs="2"/>
     34                     <xs:element name="Optional" type="xs:string" minOccurs="0"/>
     35             </xs:sequence>
     36     </xs:complexType>
     37     <xs:element name="Root" type="RootType" xdb:defaultTable="ROOT_TABLE"/>
     38  </xs:schema>'));
     39  end;
     40  / 
     
    PL/SQL procedure successfully completed.
     
    SQL> --
    SQL> -- Valid Document
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <MinOccurs>2</MinOccurs>
     11     <Optional>Goodbye</Optional>
     12  </Root>'
     13  ))
     14  / 
     
    1 row created.
     
    SQL> --
    SQL> -- Undefined element 'Illegal'
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Illegal>Hello World</Illegal>
      5     <Enumeration>A</Enumeration>
      6     <MinLength>ABCD</MinLength>
      7     <MaxLength>WXYZ</MaxLength>
      8     <MaxOccurs>1</MaxOccurs>
      9     <MaxOccurs>2</MaxOccurs>
     10     <MinOccurs>1</MinOccurs>
     11     <MinOccurs>2</MinOccurs>
     12     <Optional>Goodbye</Optional>
     13  </Root>'
     14  ))
     15  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-30937: No schema definition for 'Illegal' (namespace '##local') in parent
    '/Root'
     
     
    SQL> --
    SQL> -- Multiple occurences of 'Optional'
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <MinOccurs>2</MinOccurs>
     11     <Optional>Goodbye</Optional>
     12     <Optional>Goodbye</Optional>
     13  </Root>'
     14  ))
     15  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-30936: Maximum number (1) of 'Optional' XML node elements exceeded
     
     
    SQL> --
    SQL> -- Missing element 'Manadatory'
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Enumeration>A</Enumeration>
      4     <MinLength>ABCD</MinLength>
      5     <MaxLength>WXYZ</MaxLength>
      6     <MaxOccurs>1</MaxOccurs>
      7     <MaxOccurs>2</MaxOccurs>
      8     <MinOccurs>1</MinOccurs>
      9     <MinOccurs>2</MinOccurs>
     10     <Optional>Goodbye</Optional>
     11  </Root>'
     12  ))
     13  / 
     
    1 row created.
     
    SQL> --
    SQL> -- Invalid Enumeration Value
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>Z</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <MinOccurs>2</MinOccurs>
     11     <Optional>Goodbye</Optional>
     12  </Root>'
     13  ))
     14  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-31038: Invalid enumeration value: "Z"
     
     
    SQL> --
    SQL> -- MinLength Violation
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABC</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <MinOccurs>2</MinOccurs>
     11     <Optional>Goodbye</Optional>
     12  </Root>'
     13  ))
     14  --
     15  -- MaxLength Violation
     16  --
     17  / 
     
    1 row created.
     
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>VWXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <MinOccurs>2</MinOccurs>
     11     <Optional>Goodbye</Optional>
     12  </Root>'
     13  ))
     14  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-30951: Element or attribute at Xpath /Root/MaxLength exceeds maximum length
     
     
    SQL> --
    SQL> -- Missing element Optional - Valid Document
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <MinOccurs>2</MinOccurs>
     11  </Root>'
     12  ))
     13  / 
     
    1 row created.
     
    SQL> --
    SQL> -- Too many instances of 'MaxOccurs'
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MaxOccurs>3</MaxOccurs>
     10     <MinOccurs>1</MinOccurs>
     11     <MinOccurs>2</MinOccurs>
     12     <Optional>Goodbye</Optional>
     13  </Root>'
     14  ))
     15  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-30936: Maximum number (2) of 'MaxOccurs' XML node elements exceeded
     
     
    SQL> --
    SQL> -- Too few instances of 'MinOccurs'
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <Optional>Goodbye</Optional>
     11  </Root>'
     12  ))
     13  / 
     
    1 row created.
     
    SQL> create trigger validateSchema
      2  before insert on ROOT_TABLE
      3  for each row
      4  begin
      5     :new.object_value.schemaValidate();
      6  end;
      7  / 
     
    Trigger created.
     
    SQL> --
    SQL> -- Valid Document
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <MinOccurs>2</MinOccurs>
     11     <Optional>Goodbye</Optional>
     12  </Root>'
     13  ))
     14  / 
     
    1 row created.
     
    SQL> --
    SQL> -- Undefined element 'Illegal'
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Illegal>Hello World</Illegal>
      5     <Enumeration>A</Enumeration>
      6     <MinLength>ABCD</MinLength>
      7     <MaxLength>WXYZ</MaxLength>
      8     <MaxOccurs>1</MaxOccurs>
      9     <MaxOccurs>2</MaxOccurs>
     10     <MinOccurs>1</MinOccurs>
     11     <MinOccurs>2</MinOccurs>
     12     <Optional>Goodbye</Optional>
     13  </Root>'
     14  ))
     15  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-30937: No schema definition for 'Illegal' (namespace '##local') in parent
    '/Root'
     
     
    SQL> --
    SQL> -- Multiple occurences of 'Optional'
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <MinOccurs>2</MinOccurs>
     11     <Optional>Goodbye</Optional>
     12     <Optional>Goodbye</Optional>
     13  </Root>'
     14  ))
     15  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-30936: Maximum number (1) of 'Optional' XML node elements exceeded
     
     
    SQL> --
    SQL> -- Missing element 'Manadatory'
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Enumeration>A</Enumeration>
      4     <MinLength>ABCD</MinLength>
      5     <MaxLength>WXYZ</MaxLength>
      6     <MaxOccurs>1</MaxOccurs>
      7     <MaxOccurs>2</MaxOccurs>
      8     <MinOccurs>1</MinOccurs>
      9     <MinOccurs>2</MinOccurs>
     10     <Optional>Goodbye</Optional>
     11  </Root>'
     12  ))
     13  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-31154: invalid XML document
    ORA-19202: Error occurred in XML processing
    LSX-00213: only 0 occurrences of particle "Mandatory", minimum is 1
    ORA-06512: at "SYS.XMLTYPE", line 345
    ORA-06512: at "XDBTEST.VALIDATESCHEMA", line 2
    ORA-04088: error during execution of trigger 'XDBTEST.VALIDATESCHEMA'
     
     
    SQL> --
    SQL> -- Invalid Enumeration Value
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>Z</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <MinOccurs>2</MinOccurs>
     11     <Optional>Goodbye</Optional>
     12  </Root>'
     13  ))
     14  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-31038: Invalid enumeration value: "Z"
     
     
    SQL> --
    SQL> -- MinLength Violation
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABC</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <MinOccurs>2</MinOccurs>
     11     <Optional>Goodbye</Optional>
     12  </Root>'
     13  ))
     14  --
     15  -- MaxLength Violation
     16  --
     17  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-31154: invalid XML document
    ORA-19202: Error occurred in XML processing
    LSX-00221: "ABC" is too short (minimum length is 4)
    ORA-06512: at "SYS.XMLTYPE", line 345
    ORA-06512: at "XDBTEST.VALIDATESCHEMA", line 2
    ORA-04088: error during execution of trigger 'XDBTEST.VALIDATESCHEMA'
     
     
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>VWXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <MinOccurs>2</MinOccurs>
     11     <Optional>Goodbye</Optional>
     12  </Root>'
     13  ))
     14  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-30951: Element or attribute at Xpath /Root/MaxLength exceeds maximum length
     
     
    SQL> --
    SQL> -- Missing element Optional - Valid Document
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <MinOccurs>2</MinOccurs>
     11  </Root>'
     12  ))
     13  / 
     
    1 row created.
     
    SQL> --
    SQL> -- Too many instances of 'MaxOccurs'
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MaxOccurs>3</MaxOccurs>
     10     <MinOccurs>1</MinOccurs>
     11     <MinOccurs>2</MinOccurs>
     12     <Optional>Goodbye</Optional>
     13  </Root>'
     14  ))
     15  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-30936: Maximum number (2) of 'MaxOccurs' XML node elements exceeded
     
     
    SQL> --
    SQL> -- Too few instances of 'MinOccurs'
    SQL> --
    SQL> insert into ROOT_TABLE values (xmltype(
      2  '<Root>
      3     <Mandatory>Hello World</Mandatory>
      4     <Enumeration>A</Enumeration>
      5     <MinLength>ABCD</MinLength>
      6     <MaxLength>WXYZ</MaxLength>
      7     <MaxOccurs>1</MaxOccurs>
      8     <MaxOccurs>2</MaxOccurs>
      9     <MinOccurs>1</MinOccurs>
     10     <Optional>Goodbye</Optional>
     11  </Root>'
     12  ))
     13  / 
    insert into ROOT_TABLE values (xmltype(
                                   *
    ERROR at line 1:
    ORA-31154: invalid XML document
    ORA-19202: Error occurred in XML processing
    LSX-00213: only 1 occurrences of particle "MinOccurs", minimum is 2
    ORA-06512: at "SYS.XMLTYPE", line 345
    ORA-06512: at "XDBTEST.VALIDATESCHEMA", line 2
    ORA-04088: error during execution of trigger 'XDBTEST.VALIDATESCHEMA'
     
     
    SQL>
  • 4. Why do I get anORA-19030 error when invoking schemaValidate() ?
    mdrake Expert
    Currently Being Moderated
    Oracle currently supports two variants of XMLType.

    The first is Schema-Based XMLType where the XMLType is constrained using an XML Schema. Content can be stored using object-based persistance or text-based persistence. Any XMLType stored in a table or column that is contrained by an XML schema during table creation will always contain schema-based XML.

    The second is Non-Schema-Based XMLType where the XMLType is not constrained by an XML Schema. Content is stored using text-based persistence. tables or columns that are not constrained by an XML Schema will always contain non-schema-based XML, even if the XML document contains the XMLSchema-instance attributes which associate the document with an XML Schema.

    A PL/SQL variable can contain Schema-Based XML or Non-Schema-Based XMLtype. If the content of the XMLType comes from a schema-based XMLType table or column or is constructed from XML text containing the approprate XMLSchema-instance attributes then the content of the XMLType will be schema based. If the content of the XMLType comes from a non-schema-based XMLType table or column or is constructed from XML text that does not contain the approprate XMLSchema-instance attributes then the content of the XMLType will be non schema based.

    The schemaValidate() and isSchemaValid() methods can only be invoked on a schema-based XMLType object.

    A non-schema based XMLType can be cast to a schema-based representation using the XMLType createSchemaBasedXML() method. If the document contains the approriate XMLSchmea-Instance attributes this cast is automatic. If the XML document does not contain the appropriate XMLSchema-instance attributes then the SchemaLocationHint or URL for the XML Schema must be explicitly supplied as a parameter to the createSchemaBasedXML() method.

    The following examples demonstrate this in more detail, The example registers a very simple XML Schema and then create 2 tables, NSB_XML and SB_XML, each with an XML column called XMLDOC.

    With the NSB_XML table the XMLDOC column is not constrained by the XML Schema. With the SB_XML table the XMLDOC is constrained the XML Schema.
    SQL> var schemaURL varchar2(256)
    SQL> var schemaPath varchar2(256)
    SQL> --
    SQL> begin
      2    :schemaURL := 'testcase.xsd';
      3    :schemaPath := '/public/testcase.xsd';
      4  end;
      5  / 
     
    PL/SQL procedure successfully completed.
     
    SQL> call dbms_xmlSchema.deleteSchema(:schemaURL,4)
      2  / 
     
    Call completed.
     
    SQL> declare
      2    res boolean;
      3    xmlSchema xmlType := xmlType(
      4  '<?xml version="1.0" encoding="UTF-8"?>
      5  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" elementFormDefault="qualified" attribute
    FormDefault="unqualified">
      6     <xs:element name="root" xdb:defaultTable="ROOT_TABLE">
      7             <xs:complexType>
      8                     <xs:sequence>
      9                             <xs:element name="child1"/>
     10                             <xs:element name="child2"/>
     11                     </xs:sequence>
     12             </xs:complexType>
     13     </xs:element>
     14  </xs:schema>
     15  ');
     16  begin
     17    if (dbms_xdb.existsResource(:schemaPath)) then
     18      dbms_xdb.deleteResource(:schemaPath);
     19    end if;
     20    res := dbms_xdb.createResource(:schemaPath,xmlSchema);
     21  end;
     22  / 
     
    PL/SQL procedure successfully completed.
     
    SQL> begin
      2    dbms_xmlschema.registerSchema
      3    (
      4      :schemaURL,
      5      xdbURIType(:schemaPath).getClob(),
      6      TRUE,TRUE,FALSE,TRUE
      7    );
      8  end;
      9  / 
     
    PL/SQL procedure successfully completed.
     
    SQL> drop table nsb_xml
      2  / 
     
    Table dropped.
     
    SQL> create table nsb_xml
      2  (
      3    xmldoc xmltype
      4  )
      5  / 
     
    Table created.
     
    SQL> drop table sb_xml
      2  / 
     
    Table dropped.
     
    SQL> create table sb_xml
      2  (
      3    xmldoc xmltype
      4  )
      5  xmltype xmldoc xmlschema "testcase.xsd" element "root"
      6  / 
     
    Table created.
     
    SQL> insert into nsb_xml values (xmltype('<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="' || :s
    chemaURL || '"><child1>foo</child1><child2>bar</child2></root>'))
      2  / 
     
    1 row created.
     
    SQL> insert into sb_xml values (xmltype('<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="' || :sc
    hemaURL || '"><child1>foo</child1><child2>bar</child2></root>'))
      2  / 
     
    1 row created.
     
    SQL> begin
      2    for x in (select xmldoc from nsb_xml) loop
      3      x.xmldoc.schemaValidate();
      4    end loop;
      5  end;
      6  / 
    begin
    *
    ERROR at line 1:
    ORA-19030: Method invalid for non-schema based XML Documents.
    ORA-06512: at "SYS.XMLTYPE", line 345
    ORA-06512: at line 3
     
     
    SQL> declare
      2    tempXML xmltype;
      3  begin
      4    for x in (select xmldoc from nsb_xml) loop
      5      tempXML := x.xmldoc.createSchemaBasedXML();
      6      tempXML.schemaValidate();
      7    end loop;
      8  end;
      9  / 
     
    PL/SQL procedure successfully completed.
     
    SQL> begin
      2    for x in (select xmldoc from sb_xml) loop
      3      x.xmldoc.schemaValidate();
      4    end loop;
      5  end;
      6  / 
     
    PL/SQL procedure successfully completed.
     
    SQL>
    As can be seen from the above when an XML document is stored in a column that is not explicitly associated with an XML schema then the content is considered non-schema-based content and must be explicitly cast into a schema-based XML before the schemaValidate() can be called...