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 ) ) ; }
This method checks the parsed document if it is valid to a given XML schema . If not an exception is thrown