George Cowe created XERCESJ-1632:
------------------------------------

             Summary: XERCES-J 2-11 beta - xsd:boolean value "1" not treated in 
the same way as "true" when dealing with XSD 1.1 assertions
                 Key: XERCESJ-1632
                 URL: https://issues.apache.org/jira/browse/XERCESJ-1632
             Project: Xerces2-J
          Issue Type: Bug
    Affects Versions: 2.11.0
         Environment: Windows 64bit
            Reporter: George Cowe


I've been using Xerces-J 2-11 with support for XML Schema 1.1 
(Xerces-J-bin.2.11.0-xml-schema-1.1-beta.zip)

I've noticed that it does not seem to treat the xsd:boolean value of "1" in the 
same way as it treats the value "true". 
"0" and "false" are treated correctly.
This is in the context of assertions only, Xerces-J 2-11 without the schema 1.1 
support seems to be ok.   

The example below demonstrates the issue. 
If 'success_ind' is true or 1 then the assertion should catch the error.

The example below passes schema validation when it shouldn't 

<?xml version="1.0" encoding="UTF-8"?>
<test:message xmlns:test="http://test/schema/v1";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://test/schema/v1 test.xsd">
  <test:success_ind>1</test:success_ind>
  <test:error>Error details appear here</test:error>
</test:message>

This example below fails schema validation as expected 

<?xml version="1.0" encoding="UTF-8"?>
<test:message xmlns:test="http://test/schema/v1";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://test/schema/v1 test.xsd">
  <test:success_ind>true</test:success_ind>
  <test:error>Error details appear here</test:error>
</test:message>


Using the schema test.xsd with the appropriate assertion

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:test="http://test/schema/v1"; 
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
   targetNamespace="http://test/schema/v1"; 
   elementFormDefault="qualified" 
   attributeFormDefault="qualified" 
   version="1.0">
   <xsd:complexType name="Message">
      <xsd:sequence>
         <xsd:element name="success_ind" type="xsd:boolean"/>
         <xsd:element name="error" type="xsd:string" minOccurs="0"/>
      </xsd:sequence>
      <xsd:assert test="if (test:success_ind = false()) then test:error else 
true()"/>
      <xsd:assert test="if (test:success_ind = true()) then not(test:error) 
else true()"/>
   </xsd:complexType>
   <xsd:element name="message" type="test:Message"/>
</xsd:schema>

Sample Code

       public boolean xmlValidate(String xmlFile, String schemaFile)
       {
              boolean valid = true;
              File validatingXMLFile = new File(xmlFile);
              File schemaXMLFile = new File(schemaFile);
              try
              {
                     StreamSource schemaDocument = new 
StreamSource(schemaXMLFile);
                     Source instanceDocument = new 
StreamSource(validatingXMLFile);
                     SchemaFactory sf = 
SchemaFactory.newInstance("http://www.w3.org/XML/XMLSchema/v1.1";);
                     Schema s = sf.newSchema(schemaDocument);
                     Validator v = s.newValidator();
                     v.validate(instanceDocument);
                     System.out.println(xmlFile + " is valid");
              } 
              catch (Exception e) 
              {
                     System.out.println(xmlFile + " is not valid, exception=" + 
e.getMessage());
                     return false;
              } 
              return valid;
       }




--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to