Reference articles on history, science, culture and more
Encyclopedia

Schematron

Rule-based validation language for XML

Schematron is a rule-based validation language for making assertions about the presence or absence of patterns in XML trees. It is a structural schema language expressed in XML using a small number of elements and XPath languages. In many implementations, Schematron XML is processed into XSLT code for deployment anywhere that XSLT can be used.

Schematron is capable of expressing constraints in ways that other XML schema languages like XML Schema and DTD cannot. For example, it can require that the content of an element be controlled by one of its siblings. Or it can request or require that the root element, regardless of what element that is, must have specific attributes. Schematron can also specify required relationships between multiple XML files. Constraints and content rules may be associated with "plain-English" (or any language) validation error messages, allowing translation of numeric Schematron error codes into meaningful user error messages. Users of Schematron define all the error messages themselves.

The current ISO recommendation is Information technology, Document Schema Definition Languages (DSDL), Part 3: Rule-based validation, Schematron (ISO/IEC 19757-3:2025).

01Uses

Constraints are specified in Schematron using an XPath-based language that can be deployed as XSLT code, making it practical for applications such as the following:

Adjunct to Structural Validation
By testing for co-occurrence constraints, non-regular constraints, and inter-document constraints, Schematron can extend the validations that can be expressed in languages such as DTDs, RELAX NG or XML Schema.
Lightweight Business Rules Engine
Schematron is not a comprehensive, Rete rules engine, but it can be used to express rules about complex structures with an XML document.
XML Editor Syntax Highlighting Rules
Some XML editors use Schematron rules to conditionally highlight XML files for errors. Not all XML editors support Schematron.

02Versions

Schematron was invented by Rick Jelliffe while at Academia Sinica Computing Centre, Taiwan. He described Schematron as "a feather duster to reach the parts other schema languages cannot reach".

The most common versions of Schematron are:

  • Schematron 1.0 (1999)
  • Schematron 1.3 (2000): This version used the namespace http://xml.ascc.net/schematron/. It was supported by an XSLT implementation with a plug-in architecture.
  • Schematron 1.5 (2001): This version was widely implemented and can still be found.
  • Schematron 1.6 (2002): This version was the base of ISO Schematron and obsoleted by it.
  • ISO Schematron (2006): This version regularizes several features, and provides an XML output format, Schematron Validation Report Language (SVRL). It uses the new namespace http://purl.oclc.org/dsdl/schematron.
  • ISO Schematron (2010)
  • ISO Schematron (2016): This version added support for XSLT2.
  • ISO Schematron (2020): This version added support for XSLT3.

03Schematron as an ISO Standard

Schematron has been standardized by the ISO as Information technology, Document Schema Definition Languages (DSDL), Part 3: Rule-based validation, Schematron (ISO/IEC 19757-3:2025).

This standard is currently not listed on the ISO Publicly Available Specifications list. Paper versions may be purchased from ISO or national standards bodies.

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

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

04Sample rule

Schematron rules can be created using a standard XML editor or XForms application. The following is a sample schema:

<schema xmlns="http://purl.oclc.org/dsdl/schematron"> <pattern> <title>Date rules</title> <rule context="Contract"> <assert test="ContractDate > current-date()">ContractDate should be in the past because future contracts are not allowed.</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.

05Implementation

Schematron schemas are suitable for use in XML Pipelines, thereby allowing workflow process designers to build and maintain rules using XML manipulation tools. The W3C's XProc pipelining language, for example, has native support for Schematron schema processing through its "validate-with-schematron" step.

Since Schematron schemas can be transformed into XSLT stylesheets, these can themselves be used in XML Pipelines which support XSLT transformation. An Apache Ant task can be used to convert Schematron rules into XSLT files.

There exists also native Schematron implementation, like the Java implementation from Innovimax/INRIA, QuiXSchematron, that also do streaming.

Watch videos about SchematronExplainers and documentaries on YouTube (opens in a new tab)

Sources and credits

This article is adapted from the Wikipedia article Schematron, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.

Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.

Continue exploring

Related topics

XML schema

An XML Schema is a description of a type of XML document, typically expressed in terms of constraints on the structure and content of documents of that type, above and beyond the basic syntactical constraints imposed by XML itself. These constraints are generally expressed using some combination of grammatical rules governing the order of elements, Boolean predicates that the content must satisfy, data types governing the content of elements and attributes, and more specialized rules such as uniqueness and referential integrity constraints.

Service Modeling Language

Service Modeling Language and Service Modeling Language Interchange Format (SML-IF) are a pair of XML-based specifications created by leading information technology companies that define a set of XML instance document extensions for expressing links between elements, a set of XML Schema extensions for constraining those links, and a way to associate Schematron rules with global element declarations, global complex type definitions, and/or model documents. The SML specification defines model concepts, and the SML-IF specification describes a packaging format for exchanging SML-based models.

Document Schema Definition Languages

Document Schema Definition Languages is a framework within which multiple validation tasks of different types can be applied to an XML document in order to achieve more complete validation results than just the application of a single technology. It is specified as a multi-part ISO/IEC Standard, ISO/IEC 19757.