code: private void checkIsValid(final Document document, final Source source) throws SAXException, IOException {
  
          final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
          final Schema schema = schemaFactory.newSchema(source);
          final Validator validator = schema.newValidator();
          validator.validate(new DOMSource(document));
      }
docs: This method checks the parsed document if it is valid to a given XML
  schema. If not, an exception is thrown
  
  @param document
  The parsed document.
  @param source
  The {@link String} representation of the XML schema file.
  @throws SAXException
  if the document is invalid
  @throws IOException
  if the input cannot be read