public boolean validateAgainst ( String xmlContent , String xsdContent ) { try { Source xsd = new SAXSource ( new InputSource ( new StringReader ( xsdContent ) ) ) ; Source xml = new SAXSource ( new InputSource ( new StringReader ( xmlContent ) ) ) ; SchemaFactory schemaFactory = SchemaFactory . newInstance ( XMLConstants . W3C_XML_SCHEMA_NS_URI ) ; Schema schema = schemaFactory . newSchema ( xsd ) ; Validator validator = schema . newValidator ( ) ; validator . validate ( xml ) ; return true ; } catch ( SAXException e ) { throw new SlimFixtureException ( false , "XML Validation failed: " + e . getMessage ( ) ) ; } catch ( IOException e ) { throw new SlimFixtureException ( e ) ; } }
Validate currently loaded xml against an xsd