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

JavaOne 2015 Session: EJB 3.2/JPA 2.1 Best Practices with Real-Life Examples by Gohar

Spring Core - Different Types of Bean Injection

PrimeFaces Push with Atmosphere