I am validating xml against xsd, when first validation error is encountered its throwing first exception, But, through this approach, we cannot get information about all validation errors in the XML file in a single run. If an XML file has multiple validation errors, then in first run, the exception will be thrown as soon as the first error will be encountered and we do not get to know about remaining errors. To know about the subsequent errors, we need to fix the previous error and validate the file again and again till no exception is thrown.
onException( SchemaValidationException.class )
.handled(true)
.to("file:invalid-data")
from("file:in-data?noop=true")
.to("validator:file:my.xsd")
.to("file:out-data");
Which Apache Camel version are you using? In 2.20, the validation code do handle all the errors after validating:
try {
LOG.trace("Validating {}", source);
validator.validate(source, result);
handler.handleErrors(exchange, schema, result);
} catch (SAXParseException e) {
throw new SchemaValidationException(exchange, schema, Collections.singletonList(e), Collections.<SAXParseException>emptyList(), Collections.<SAXParseException>emptyList());
}
The validation is performed by javax.xml.validation.Validator
class, though. Please see this question that has a similar discussion. The docs stated that:
Errors found during the validation is sent to the specified ErrorHandler. If a document is valid, or if a document contains some errors but none of them were fatal and the ErrorHandler didn't throw any exception, then the method returns normally.
Maybe the errors you are facing are fatal? If it's the case, I think that's out of Camel's component control. :(