Title: When unmarshalling, need Castor to validate entire document against schema instead of quitting after first validation error

Hi

I would like to validate my entire instance document against an XML schema during the unmarshalling process and accumulate all the validation exceptions so that I may send them back to the document creator so they may all be fixed.  Right now, Castor is throwing the first ValidationException and stopping the schema validation process.  Is there a way to tell Castor to validate the entire document before stopping (i.e. make a ValidationException a non-fatal error)?

My Castor driver method:

                //unmarshal xml
                boolean isSuccessful = true;
               
                Reader toParse = new StringReader((String) xmlToParse);

                try
                {              
                        Mapping mapping = new Mapping();
                        mapping.loadMapping(mapFileName);
                        Unmarshaller un = new Unmarshaller(castorClass);
                        un.setMapping(mapping );
                        un.setWhitespacePreserve(true);
                        un.setValidation(true);
                        try
                        {
                                castorVO = (AbstractCastorVO) un.unmarshal(toParse);
                        }
                        catch (ValidationException ex)
                        {
                                parserMessageList.add(ex.getMessage());
                        }
                        catch(MarshalException ex)
                        {
                                parserMessageList.add(ex.getMessage());
                        }

                        toParse.close();               
                }              
               
                catch (IOException ex)
                {
                        isSuccessful = false;
                        parserMessageList.add(ex.getMessage());
                }
                catch (MappingException ex)
                {
                        isSuccessful = false;
                        parserMessageList.add(ex.getMessage());
                }
                catch (MarshalException ex)
                {
                        isSuccessful = false;
                        parserMessageList.add(ex.getMessage());
                }
               
                return isSuccessful;


My castor.properties settings:

# True if xml documents should be validated by the SAX Parser
#
org.exolab.castor.parser.validation=true

# Per Patty - set to false when generating code
# then set to true for un/marshalling
org.exolab.castor.parser.namespaces=true


# True if all documents should be validated by the marshalling framework
#
org.exolab.castor.marshalling.validation=true
org.exolab.castor.unmarshalling.validation=true

org.exolab.castor.sax.features=http://xml.org/sax/features/validation,\
        http://apache.org/xml/features/validation/schema,\
        http://apache.org/xml/features/validation/schema-full-checking

# Comma separated list of SAX 2 features that should be enabled
# for the default parser.
#
#org.exolab.castor.features=

Thank you for your help

Patty

Reply via email to