Code example for Validator

Methods: setErrorHandlervalidate

0
    InputSource is = new InputSource(reader);
    SAXSource source = new SAXSource(is);
 
    // validate the XML 
    ValidationErrorHandler errorHandler = new ValidationErrorHandler();
    validator.setErrorHandler(errorHandler);
    try { 
      validator.validate(source);
    } 
    catch (IOException exc) { exception = exc; }
    catch (SAXException exc) { exception = exc; }
    final int errors = errorHandler.getErrorCount();
    if (errors > 0) {
      LOGGER.info("Error validating document: {} errors found", errors);
      return false; 
    } 
    else LOGGER.info("No validation errors found."); 
    return errorHandler.ok();
  }