The ISO Schematron standard has been out for two years now, but I\'m still unable to find a Java implementation using ISO Schematron XSLT files (as opposed to files from an
Probatron4j can validate against ISO Schematron. The website provides a single, self-contained JAR that's designed to be run from the command line, but it's easy to call Probatron from a Java method if you have its source code. Here's a simplified version of how I did it:
public boolean validateSchematron(InputStream xmlDoc, File schematronSchema) {
// Session = org.probatron.Session; think of it as the Main class
Session theSession = new Session();
theSession.setSchemaSysId(schematronSchema.getName());
theSession.setFsContextDir(schematronSchema.getAbsolutePath());
// ValidationReport = org.probatron.ValidationReport; the output class
ValidationReport validationReport = null;
try
{
validationReport = theSession.doValidation(xmlDoc);
}
catch(Exception e) { /* ignoring to keep this answer short */ }
if (validationReport == null ||
!validationReport.documentPassedValidation()) {
return false;
}
return true;
}
You'll need to make a few minor modifications to let Probatron know it's not being run from within a JAR file, but it doesn't take long.