views:

160

answers:

1

Hello,

i would like to get all validation Errors from the SAX-Parser, but with my snippet i only receive the first. How can i achieve this?

Thank you!

Snippet

def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
def xml = new StreamSource(inputStream)
def xsd = new StreamSource(new FileReader(schema), systemId)

try {
 factory?.newSchema(xsd)?.newValidator()?.validate(xml)
} catch(SAXParseException saxpe) {
    continueImport = false
 log.error("Error while parsing the import xml", saxpe)
}
+5  A: 

Have you tried implementing an ErrorHandler ? This will let you receieve and record errors/warnings and fatal errors.

From the doc:

If a SAX application needs to implement customized error handling, it must implement this interface and then register an instance with the XML reader using the setErrorHandler method. The parser will then report all errors and warnings through this interface.

Brian Agnew