Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to display multiple XML errors during XSD validation?

800336Feb 22 2010 — edited Feb 26 2010
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());
	}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 26 2010
Added on Feb 22 2010
18 comments
1,732 views