4 Replies Latest reply on Sep 6, 2013 9:10 AM by sush007

    XSD validation fails on a regex for valid data

    987833
      Hello,

      For whatever reason the following regex expression is falling for 5095.0000

      <xs:pattern value="[0-9]{1,4}[.][0-9]{4}"/>

      Please advise.

      This is the XML:
      <?xml version="1.0" encoding="iso-8859-1"?>
      <root DataFeedDate="2013-02-11" xmlns="http://www.abccompany.com">
           <r>
                <ExchangeRateUSD>5095.0000</ExchangeRateUSD>
           </r>
      </root>
      This is the XSD:
      <?xml version="1.0" encoding="UTF-8"?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="0.92" 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="ExchangeRateUSD" minOccurs="0"/>
                     </xs:sequence>
                </xs:complexType>
           </xs:element>
           <xs:element name="ExchangeRateUSD">
                <xs:simpleType>
                     <xs:restriction base="xs:decimal">
                          <xs:totalDigits value="8"/>
                          <xs:fractionDigits value="4"/>
                          <xs:pattern value="[0-9]{1,4}[.][0-9]{4}"/>
                     </xs:restriction>
                </xs:simpleType>
           </xs:element>
      </xs:schema>
      This is the error:
      ORA-31154: invalid XML document
      ORA-19202: Error occurred in XML processing
      LSX-00333: literal "5095" is not valid with respect to the pattern
      ORA-31154: invalid XML document
      ORA-19202: Error occurred in XML processing
      LSX-00333: literal "5095" is not valid with respect to the pattern
      
      ORA-06512: at "SYS.XMLTYPE", line 354
      ORA-06512: at line 7
      This is the XSD registration and validation:
      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  
        );
      end;
      
      
      declare
        l_xml xmltype;
      begin
        L_XML := XMLTYPE(BFILENAME('TMP','SpendAnalysis.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);
                DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_ERROR_STACK);          
                DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
      end;
        • 1. Re: XSD validation fails on a regex for valid data
          odie_63
          I can reproduce on 11.2.0.2, what's your db version?

          Seems to work better if we use the following option while registering the schema :
          options => dbms_xmlschema.REGISTER_BINARYXML
          • 2. Re: XSD validation fails on a regex for valid data
            987833
            The version is:
            select * from v$version;
            
            BANNER                                                                         
            --------------------------------------------------------------------------------
            Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production           
            PL/SQL Release 11.2.0.1.0 - Production                                           
            CORE     11.2.0.1.0     Production                                                         
            TNS for Linux: Version 11.2.0.1.0 - Production                                   
            NLSRTL Version 11.2.0.1.0 - Production        
            I added the option and It was fix it!
            begin
              DBMS_XMLSCHEMA.DELETESCHEMA(
                schemaURL => 'http://abccompany.com/SpendAnalysis.xsd'
               ,delete_option=>dbms_xmlschema.delete_cascade_force     
               );
            end;
            
            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;
            • 3. Re: XSD validation fails on a regex for valid data
              988118
              Good thing is that the Regex is working when it is specified like recommended:
              options => dbms_xmlschema.REGISTER_BINARYXML
              Overall, it looks like a bug.
              Why would a simple regular expression won't work just as is.

              Edited by: 985115 on Feb 13, 2013 10:43 AM
              • 4. Re: XSD validation fails on a regex for valid data
                sush007

                Hi

                 

                I am facing same issue and i am using Oracle 11.2.0.2 and I am registering Schema using

                 

                options => dbms_xmlschema.REGISTER_BINARYXML

                 

                this option. Then i am also getting same error.

                 

                ORA-31154: invalid XML document
                ORA-19202: Error occurred in XML processing

                LSX-00333: literal is not valid with respect to the pattern