SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); // TODO: null???
Schema schema = null;
try {
schema = factory.newSchema(getSchema(request));
} catch (SAXException e) {
throw new DataProvidingException("error parsing XML schema", e);
}
Validator validator = schema.newValidator();
CollectingErrorHandler collector = new CollectingErrorHandler();
validator.setErrorHandler(collector);
try {
validator.validate(new DOMSource(retval)); // TODO: can also accept additional Result arg. why?
} catch (IOException e) {
throw new DataProvidingException("error reading xml source", e);
} catch (SAXException e) {
throw new DataProvidingException("error validating xml", e);
}
// now check if any warnings or errors have been collected
String msg = collector.getCombinedMessage(isFailOnWarning(request));
if (StringUtils.isNotBlank(msg)) {
throw new ValidationException("xml validation errors:\n" + msg);