Alison,

based upon the XML schema fragment given below, I thin that Castor is correct. In other words, if a <FilmReference> element is present in your XML document instance, it will have to be non-empty. That's exactly what your XML schema definition for <FilmReference> defines. Other than changing your element definition, there's no way out. Remember that empty tags imply that the element in question is present, and thus needs to conform with the rules defined.

Werner

Rimmer, Alison wrote:
I have a field defined as non-mandatory, but also has some details of the type of data it should contain if it exists:

[schema snippet]
<element name="FilmReference" minOccurs="0">
        <simpleType>
                <restriction base="string">
                        <minLength value="1"/>
                        <maxLength value="11"/>
                        <pattern value="[*0-9 A-Z]*"/>
                </restriction>
        </simpleType>
</element>

I used Castor 1.1.1 to generate the classes from the schema, which I then use for unmarshalling (including descriptors).

If the XML I receive contains no 'FilmReference' tag it unmarshalls and validates successfully, but if it contains an empty tag, it fails with the following error:

The following exception occured while validating field: _possibleMatchList of class: com.btc.ba.fileinterface.possiblematches.PossibleMatches: The following exception occured while validating field: _usage of class: com.btc.ba.fileinterface.possiblematches.PossibleMatch: The following exception occured while validating field: _filmReference of class: com.btc.ba.fileinterface.possiblematches.Usage: Strings of this type must have a minimum length of 1 characters{File: [not available]; line: 41998; column: 22}

at org.exolab.castor.xml.Unmarshaller.convertSAXExceptionToMarshalException(Unmarshaller.java:775) at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:741) at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:621) at com.btc.ba.fileinterface.DataLoader.processPossibleMatches(DataLoader.java:223) at com.btc.ba.fileinterface.DataLoader.processFile(DataLoader.java:181)
        at com.btc.ba.fileinterface.DataLoader.run(DataLoader.java:128)
at com.btc.ba.fileinterface.ProcessController.doProcessing(ProcessController.java:127) at com.btc.ba.fileinterface.ProcessController.run(ProcessController.java:68) Caused by: ValidationException: The following exception occured while validating field: _possibleMatchList of class: com.btc.ba.fileinterface.possiblematches.PossibleMatches: The following exception occured while validating field: _usage of class: com.btc.ba.fileinterface.possiblematches.PossibleMatch: The following exception occured while validating field: _filmReference of class: com.btc.ba.fileinterface.possiblematches.Usage: Strings of this type must have a minimum length of 1 characters;

   - location of error: XPATH: /PossibleMatches
The following exception occured while validating field: _usage of class: com.btc.ba.fileinterface.possiblematches.PossibleMatch: The following exception occured while validating field: _filmReference of class: com.btc.ba.fileinterface.possiblematches.Usage: Strings of this type must have a minimum length of 1 characters

at org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:270) at org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:1048)
        at org.exolab.castor.xml.Validator.validate(Validator.java:127)
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:921) at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:1119) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:729)
        ... 6 more
Caused by: ValidationException: The following exception occured while validating field: _usage of class: com.btc.ba.fileinterface.possiblematches.PossibleMatch: The following exception occured while validating field: _filmReference of class: com.btc.ba.fileinterface.possiblematches.Usage: Strings of this type must have a minimum length of 1 characters;

   - location of error: XPATH: /PossibleMatch
The following exception occured while validating field: _filmReference of class: com.btc.ba.fileinterface.possiblematches.Usage: Strings of this type must have a minimum length of 1 characters

at org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:270) at org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:1048)
        at org.exolab.castor.xml.Validator.validate(Validator.java:127)
at org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:237)
        ... 19 more
Caused by: ValidationException: The following exception occured while validating field: _filmReference of class: com.btc.ba.fileinterface.possiblematches.Usage: Strings of this type must have a minimum length of 1 characters;

   - location of error: XPATH: /Usage
Strings of this type must have a minimum length of 1 characters
at org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:270) at org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:1048)
        at org.exolab.castor.xml.Validator.validate(Validator.java:127)
at org.exolab.castor.xml.FieldValidator.validateInstance(FieldValidator.java:318) at org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:263)
        ... 22 more
Caused by: ValidationException: Strings of this type must have a minimum length of 1 characters at org.exolab.castor.xml.validators.StringValidator.validate(StringValidator.java:292) at org.exolab.castor.xml.validators.StringValidator.validate(StringValidator.java:340) at org.exolab.castor.xml.FieldValidator.validateInstance(FieldValidator.java:316) at org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:263)
        ... 26 more
[truncated]

I would have expected empty tags for non-mandatory fields to be ignored, but this does not seem to be the case. Is there anything I can do about this (other than asking the customer not to send empty tags)?

regards,

Alison


$$
BancTec Ltd
Reg Office: Jarman House, Mathisen Way, Poyle Road, Colnbrook, Berkshire SL3 0HF. Incorporated in England & Wales - 1283512. VAT GB 228 4783 38.
______________________________________________________________________


---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to