I have configured my castor.properties file so that I’m now getting my XML
documents validated against the Schema when I unmarshall, by adding these
lines:

org.exolab.castor.parser.namespaces=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

But I notice that I get a “MarshalException” when the document fails to
validate, instead of a “ValidationException”. For example:

*org.exolab.castor.xml.MarshalException*: cvc-enumeration-valid: Value
'PFPa' is not facet-valid with respect to enumeration '[PFP, MTBS]'. It must
be a value from the enumeration.{File: [not available]; line: 6; column: 54}

      at
org.exolab.castor.xml.Unmarshaller.convertSAXExceptionToMarshalException(*
Unmarshaller.java:794*)

      at org.exolab.castor.xml.Unmarshaller.unmarshal(*Unmarshaller.java:760
*)

      at org.exolab.castor.xml.Unmarshaller.unmarshal(*Unmarshaller.java:626
*)

      at org.CastorTest.validateXml(*CmhToStamps.java:378*)

      at org.CastorTest.testMarshallGeneric(*CmhToStamps.java:242*)

      at org.CastorTest.main(*CmhToStamps.java:55*)

Caused by: *org.xml.sax.SAXParseException*: cvc-enumeration-valid: Value
'PFPa' is not facet-valid with respect to enumeration '[PFP, MTBS]'. It must
be a value from the enumeration.

      at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)

      at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)

      ...

      (etc.)

That’s fine, but ideally I’d like the XML parser to inform me of **all**
validation errors, not just the first one it comes across. And looking at
the ValidationException class, I see a getNext() method which looks like it
was meant to support this feature! So how do I get Castor to throw a
ValidationException when my XML document fails validation?

Or another way of putting it is, is there a way for me to validate XML
documents with Castor so that I find out about **all** problems, and not
just the first one? I’m ok changing XML parsers, if that’s what’s needed.

-Steve

p.s. – I’m using the latest version of Castor, and Xerces.

Reply via email to