Schematron

From Wikipedia, the free encyclopedia

In Markup Languages, Schematron is a rule-based validation language for making assertions about the presence or absence of patterns in XML trees. It is a simple and powerful structural schema language. It typically uses XPath to describe patterns.

Contents

[edit] Advantages

Because of its rule-based nature, Schematron's specificity is very strong. It can require that the content of an element be controlled by one of its siblings. It can, also, request or require that the root element, regardless of what element that happens to be, have specific attributes. It can even specify required relationships between multiple XML files.

[edit] Uses

Because of its simple, lightweight design and reuse of existing XML standards such as XPath, Schematron can be used for many purposes. Some of these include the following areas.

[edit] Adjunct to Structural Validation

Schematron can be used as an adjunct to DTDs, RELAX NG or XML Schema. It allows co-occurrence constraints, non-regular constraints, and inter-document constraints.

[edit] Lightweight Business Rules Engine

Schematron is used to express lightweight business rules. Schematron is not a full heavyweight Rete rules engine but can be used to express rules about complex structures with an XML document.

[edit] XML Editor Syntax Highlighting Rules

XML Editors use Schematron rules to conditionally highlight XML files for errors.

[edit] History

Schematron was invented by Rick Jelliffe. He described Schematron as "a feather duster to reach the parts other schema languages cannot reach".

[edit] Schematron as an ISO Standard

Schematron has been standardized to become part of 
ISO/IEC 19757 - Document Schema Definition Languages (DSDL) - Part 3: Rule-based validation - Schematron.

[edit] Namespace Standard

Any files that use ISO/IEC FDIS 19757-3 should use the following namespace:

http://purl.oclc.org/dsdl/schematron

[edit] Sample Rule

Schematron rules are very simple to create using a standard XML editor or XForms application. The following is a sample rule:

<schema xmlns="http://purl.oclc.org/dsdl/schematron">
   <pattern name="Contract date must be in the past">
      <rule context="Contract">
         <assert test="ContractDate &lt; current-date()">ContractDate must be in the past.</assert>
      </rule>
   </pattern>
</schema>

This rule checks to make sure that the ContractDate XML element has a date that is before the current date. If this rule fails the validation will fail and an error message which is the body of the assert element will be returned to the user.

[edit] Implementation

Schematron source files are usually transformed into XSLT files (using XSLT) and placed in an XML Pipeline. This allows workflow process designers to build and maintain rules using standard XML manipulation tools.

For example an Apache Ant task can be used to convert Schematron rules into XSLT files.

[edit] See also

[edit] External links

Languages