public static boolean validateSchema ( final String SchemaUrl , final String XmlDocumentUrl ) throws SAXException , ParserConfigurationException , IOException { System . setProperty ( DOCUMENT_BUILDER_FACTORY_KEY , DOCUMENT_BUILDER_FACTORY_VALUE ) ; final DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; factory . setNamespaceAware ( true ) ; factory . setValidating ( true ) ; factory . setAttribute ( SCHEMA_LANGUAGE_KEY , HTTP_WWW_W3_ORG_2001_XML_SCHEMA ) ; factory . setAttribute ( SCHEMA_SOURCE_KEY , SchemaUrl ) ; final DocumentBuilder builder = factory . newDocumentBuilder ( ) ; final ValidatorHandler handler = new ValidatorHandler ( ) ; builder . setErrorHandler ( handler ) ; builder . parse ( XmlDocumentUrl ) ; if ( handler . isValid ( ) ) { return false ; } return true ; }
Validate given xml schema .