Where can I find the Java implementation for Schematron ISO authentication?

The ISO Schematron standard has been around for two years, but I still can’t find a Java implementation using the Schematron XSLT ISO files (unlike files from an older version of Schematron, for example here: http://uploading.com/files/c9c9cb87/SchematronXpath .jar / ).

Does anyone know about an ISO ready-to-release schema that can be easily called from a Java method?

+3
java schematron
source share
4 answers

In addition, you can use ph-schematron , which provides both support for conversion to XSLT, and its own regular Java check, which runs faster than the XSLT version in almost all cases. See https://github.com/phax/ph-schematron/ for more details, as well as a brief introduction. Sample code to verify that an XML file matches a Schematron file:

 public static boolean validateXMLViaPureSchematron (File aSchematronFile, File aXMLFile) throws Exception { final ISchematronResource aResPure = SchematronResourcePure.fromFile (aSchematronFile); if (!aResPure.isValidSchematron ()) throw new IllegalArgumentException ("Invalid Schematron!"); return aResPure.getSchematronValidity(new StreamSource(aXMLFile)).isValid (); } 
+9
source share

Probatron4j can verify compliance with ISO Schematron. The website provides a single standalone JAR that is designed to be run from the command line, but it is easy to call Probatron from the Java method if you have its source code . Here is a simplified version of how I did this:

 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 need to make a few minor changes so that Probatron does not know that it does not start from the JAR file, but it does not take much time.

+5
source share

You can check out SchematronAssert (expansion: my code). It is intended primarily for unit testing, but you can also use it for regular code. It is implemented using XSLT.

Device Test Example:

 ValidationOutput result = in(booksDocument) .forEvery("book") .check("author") .validate(); assertThat(result).hasNoErrors(); 

Standalone verification example:

 StreamSource schemaSource = new StreamSource(... your schematron schema ...); StreamSource xmlSource = new StreamSource(... your xml document ... ); StreamResult output = ... here your SVRL will be saved ... // validation validator.validate(xmlSource, schemaSource, output); 

Working with the SVRL Object View:

 ValidationOutput output = validator.validate(xmlSource, schemaSource); // look at the output output.getFailures() ... output.getReports() ... 
0
source share

The jing library works for me.

-one
source share

All Articles