posted 12 years ago
I am validating an XML file against a schema. I have an ErrorHandler handling the error messages and logging the errors. What I am wondering is, after the validation is done and the errors are printed, how do I know whether the document is valid? Here is my code:
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(new SimpleErrorHandler());
Document document = builder.parse(new InputSource(new StringReader(modifyXML)));
//check to see whether validation was successful
public class SimpleErrorHandler implements ErrorHandler {
private Logger logger = Logger
.getLogger("com.bwi.oddr.activity.ValidateMessageActivity");
public void warning(SAXParseException e) throws SAXException {
logger.warn(e.getMessage());
}
public void error(SAXParseException e) throws SAXException {
logger.error(e.getMessage());
}
public void fatalError(SAXParseException e) throws SAXException {
logger.fatal(e.getMessage());
}
}
It looks like an empty document is passed back from the parse method even if the validation failed. So what is the best way to check the Document to see if the validation was successful or not?