How can I check documents on Schematron diagrams in Java?

As far as I can tell, JAXP by default supports W3C XML Schema and RelaxNG from Java 6 .

I see several APIs, mostly experimental or incomplete, on the schematron.com page.

Is there an approach to validating a schema in Java that is complete, efficient, and can be used with the JAXP API?

+6
java validation schema schematron jaxp
source share
3 answers

Jing supports Schematron pre-validation (note that the Jing implementation is also based on XSLT).

There are also XSLT implementations that can be called very easily from Java. You need to decide which version of Schematron you are interested in, and then get the appropriate stylesheet - they should all be available on schematron.com. The process is very simple, including basically 2 steps:

  • apply the XSLT skeleton on your Schematron schema to get a new XSLT stylesheet that represents your Schematron schema in XSLT
  • apply the resulting XSLT in the instance document or documents to validate them

JAXP is just an API, and it does not require Relax NG support from the implementation. You need to check the specific implementation that you are using to see if Relax NG supports or not.

+6
source share

A pure Java implementation of Schematron is located at https://github.com/phax/ph-schematron/. It provides support for both the XSLT approach and the pure Java approach.

+2
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() ... 
+1
source share

All Articles