How to validate XML file against XSD in Java

private boolean validateAgainstXSD(InputStream xml, InputStream xsd) {
 try {
         SchemaFactory factory = 
         Schema schema = factory.newSchema(new StreamSource(xsd));
         Validator validator = schema.newValidator();
         validator.validate(new StreamSource(xml));
         return true;
 catch(Exception ex) {
     return false;


Popular posts from this blog

PrimeFaces Push with Atmosphere

Adding MyBatis mapper files dynamically

Creating JSF/CDI Maven project on Eclipse