Hi,
I'm validating XML string against XSD using Validator class. My problem is the validation stops wherever first error is encountered. I would like to display all errors in one go. Any one has a suggestion?
Here is what I have written:
public void validateXML(final String xmlMessage) throws Exception {
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(new InputSource(new ByteArrayInputStream(xmlMessage.getBytes())));
Schema schema = factory.newSchema(source);
Validator validator = schema.newValidator();
// Validate the xml message
validator.validate(new DOMSource(document));
}
catch (ParserConfigurationException e) {
logger.error("ParserConfigurationException : " + e.getMessage());
}
catch (SAXException e) {
logger.error("SAXException : " + e.getMessage());
}
catch (IOException e) {
logger.error("IOException : " + e.getMessage());
}
}