9 Replies Latest reply: Apr 12, 2013 8:46 AM by 988118 RSS

    XSD validation: minExclusive facet for decimal data type gives LSX-00291

    987833
      I am trying to make sure that UnitPriceUSD data element value is > than zero.

      select * from v$version
      Oracle Version:
      Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
      PL/SQL Release 11.2.0.2.0 - Production
      "CORE   11.2.0.2.0            Production"
      TNS for HPUX: Version 11.2.0.2.0 - Production
      NLSRTL Version 11.2.0.2.0 - Production
      The XML file:
      <?xml version="1.0" encoding="iso-8859-1"?><root DataFeedDate="2013-03-06" xmlns="http://www.abccompany.com">
        <r>
          <UnitPriceUSD>0.00056</UnitPriceUSD>
        </r>
      </root>
      The XSD file:
      <?xml version="1.0" encoding="UTF-8"?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="0.96" targetNamespace="http://www.abccompany.com" xmlns="http://www.abccompany.com">
           <xs:element name="root">
                <xs:complexType>
                     <xs:sequence>
                          <xs:element ref="r" maxOccurs="unbounded"/>
                     </xs:sequence>
                     <xs:attribute name="DataFeedDate" use="required" type="xs:date"/>
                </xs:complexType>
           </xs:element>
           <xs:element name="r">
                <xs:complexType>
                     <xs:sequence>
                          <xs:element ref="UnitPriceUSD"/>
                     </xs:sequence>
                </xs:complexType>
           </xs:element>
           <xs:element name="UnitPriceUSD">
                <xs:simpleType>
                     <xs:restriction base="xs:decimal">
                          <xs:totalDigits value="15"/>
                          <xs:fractionDigits value="5"/>
                          <xs:minExclusive value="0.00000"/>
                     </xs:restriction>
                </xs:simpleType>
           </xs:element>
      </xs:schema>
      Register the XSD in Oracle:
      begin
        dbms_xmlschema.registerSchema(
          schemaURL => 'http://abccompany.com/SpendAnalysis.xsd'
        , schemaDoc => xmltype(bfilename('TMP','SpendAnalysis.xsd'), nls_charset_id('AL32UTF8'))
        , local => true
        , genTypes => false
        , genTables => false
        , enablehierarchy => dbms_xmlschema.enable_hierarchy_none  
        , options => dbms_xmlschema.register_binaryxml  
        );
      end;
      Validate the XML file with the XSD:
      declare
        l_xml xmltype;
      begin
        l_xml := xmltype(bfilename('TMP','CO_SPEND_ANALYSIS.XML'), nls_charset_id('WE8ISO8859P1'));
       
        l_xml := l_xml.createSchemaBasedXML('http://abccompany.com/SpendAnalysis.xsd');
        
        l_xml.schemaValidate();
        DBMS_OUTPUT.PUT_LINE('XML IS VALID.');
        exception when others then
        DBMS_OUTPUT.PUT_LINE(SQLerrm);
       
      end;
      XSD validation error: "Document XML not valid, It has produce a error in the processing:"
      ORA-31154: documento XML no válido
      ORA-19202: Se ha producido un error en el procesamiento 
      LSX-00291: value "0.00056" is less than minimum "0.00000" (exclusive)
      de XML