dbms_xmlschema fail to validate with complexType

Posted by Andrew on Stack Overflow See other posts from Stack Overflow or by Andrew
Published on 2010-05-12T10:38:02Z Indexed on 2010/05/12 10:44 UTC
Read the original article Hit count: 276

Filed under:
|

Preface: This works on one Oracle 11gR1 (Solaris 64) database and not on a second and we can't figure out the difference between the two databases. Somehow the complexType causes the validation to fail with this error:

ORA-31154: invalid XML document ORA-19202: Error occurred in XML processing LSX-00200: element "shiporder" not empty ORA-06512: at "SYS.XMLTYPE", line 354 ORA-06512: at line 13

But the schema is valid (passes this online test: http://www.xmlme.com/Validator.aspx)

-- Cleanup any existing schema
begin
dbms_xmlschema.deleteschema('shiporder.xsd',dbms_xmlschema.DELETE_CASCADE);
end;


-- Define the problem schema (adapted from http://www.w3schools.com/schema/schema_example.asp)
begin
dbms_xmlschema.registerSchema('shiporder.xsd','<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="shiporder">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="orderperson" type="xs:string"/>
     </xs:sequence>
  </xs:complexType>
</xs:element>


</xs:schema>',owner=>'SCOTT');
end;

-- Attempt to validate
declare
bbb xmltype;
begin

bbb := XMLType('<?xml version="1.0" encoding="ISO-8859-1"?>

<shiporder 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
  <orderperson>John Smith</orderperson>
</shiporder>');

        XMLType.schemaValidate(bbb);
end;

Now if I gut the schema definition and leave only a string in the XML then the validation passes:

begin
dbms_xmlschema.deleteschema('shiporder.xsd',dbms_xmlschema.DELETE_CASCADE);
end;


begin
dbms_xmlschema.registerSchema('shiporder.xsd','<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="shiporder" type="xs:string"/>

</xs:schema>',owner=>'SCOTT');
end;

DECLARE
    xml XMLTYPE;
BEGIN

xml := XMLTYPE('<?xml version="1.0" encoding="ISO-8859-1"?>

<shiporder 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
  John Smith
</shiporder>');

    XMLTYPE.schemaValidate(xml);
END;

© Stack Overflow or respective owner

Related posts about oracle11g

Related posts about dbms-xmlschema