You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Schematron Component

Available as of Camel 2.14

Schematron is an XML-based language for validating XML instance documents. It is used to make assertions about data in an XML document and it is also used to express operational and business rules. Schematron is an ISO Standard. The schematron component uses the leading implementation of ISO schematron. It is an XSLT based implementation. The schematron rules is run through four XSLT pipelines, which generates a final XSLT which will be used as the basis for running the assertion against the XML document.

URI format

schematron://path?[options]

URI options

NameDefault valueDescription
pathmandatoryThe path to the schematron rules file. Can either be in class path or location in the file system.
abortfalseflag to abort the route and throw a schematron validation exception.

Headers

NameDescriptionTypeIn/Out
CamelSchematronValidationStatusThe schematron validation status: SUCCESS / FAILEDStringIN
CamelSchematronValidationReportThe schematrion report body in XML format. See an example belowStringIN

URI and path syntax

The following example shows how to invoke the schematron processor in Java DSL. The schematron rules file is sourced from the class path:

from("direct:start").to("schematron://sch/schematron.sch").to("mock:result")

 

The following example shows how to invoke the schematron processor in XML DSL. The schematrion rules file is sourced from the file system:

<route>
   <from uri="direct:start" />
   <to uri="schematron:///usr/local/sch/schematron.sch" />
   <log message="Schematron validation status: ${in.header.CamelSchematronValidationStatus}" />
   <choice>
      <when>
         <simple>${in.header.CamelSchematronValidationStatus} == 'SUCCESS'</simple>
         <to uri="mock:success" />
      </when>
      <otherwise>
         <log message="Failed schematron validation" />
         <setBody>
            <header>CamelSchematronValidationReport</header>
         </setBody>
      </otherwise>
   </choice>
</route>

Schematron rules file location good practice

Schematron rules can change with business requirement, as such it is recommended to store these rules somewhere in file system. When the schematron component endpoint is started, the rules are compiled into XSLT as a  Java Template Object. This is done only once to minimise the overhead of instantiating Java Template object which can be an expensive operation for large set of rules and given that the process goes through four pipelines

Brief tutorial of schematron

Here is an example of schematron rules

schematron rules
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
   <title>Check Sections 12/07</title>
   <pattern id="section-check">
      <rule context="section">
         <assert test="title">This section has no title</assert>
         <assert test="para">This section has no paragraphs</assert>
      </rule>
   </pattern>
</schema>

 

 

 

 

  • No labels