Hi

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;
       }


Can someone get back to me and let me know if this is a bug please?

Thanks
George



George Cowe
Technical Architect
Origo Services Ltd
Moyen House
Heriot-Watt Research Park North
Edinburgh EH14 4AP

0131 451 5181
0131 451 1179  (Direct)
[email protected]<mailto:[email protected]>


E-mail disclaimer

The information in this e-mail is sent in confidence for the addressee only and 
may be legally privileged. Unauthorised recipients must preserve this 
confidentiality and should please advise the sender immediately of the error in 
transmission and then delete this e-mail. If you are not the intended 
recipient, any disclosure, copying, distribution or any action taken in 
reliance on its content is prohibited and may be unlawful.

Origo Services Limited accepts no responsibility for any loss or damage 
resulting directly or indirectly from the use of this e-mail or the contents. 
It is your responsibility to scan for viruses. Origo Services Limited reserves 
the right to monitor e-mails sent to or from addresses under its control. When 
you reply to this e-mail, you are consenting to Origo Services Limited 
monitoring the content of the e-mails you send to or receive from Origo 
Services Limited. If this e-mail is non-business related Origo Services Limited 
is not liable for any opinions expressed by the sender. The contents of this 
e-mail are protected by copyright. All rights reserved.

Origo Services Limited is a company incorporated in Scotland (company number 
115061) having its registered office at Moyen House, Heriot Watt Research Park 
North, Edinburgh, EH14 4AP

Reply via email to