views:

66

answers:

1

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

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

    <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;
A: 

Solution turned out to be to rebuild XDB but when doing so to make sure no Oracle processes were hanging around on the server because they prevent XDB from being built correctly and cause the validator to fail.

Andrew