Schematron is a rule-based
validation language for making assertions about the presence or absence of patterns in
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
trees. It is a structural schema language expressed in XML using a small number of elements and
XPath
XPath (XML Path Language) is an expression language designed to support the query or transformation of XML documents. It was defined by the World Wide Web Consortium (W3C) in 1999, and can be used to compute values (e.g., strings, numbers, or ...
languages. In many implementations, Schematron XML is processed into
XSLT
XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text, or XSL Formatting Objects. These formats c ...
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
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 constrai ...
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
The International Organization for Standardization (ISO ; ; ) is an independent, non-governmental, international standard development organization composed of representatives from the national standards organizations of member countries.
Me ...
recommendation is ''Information technology, Document Schema Definition Languages (DSDL)'', Part 3: ''Rule-based validation, Schematron'' (ISO/IEC 19757-3:2020).
Uses
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
In computing, RELAX NG (REgular LAnguage for XML Next Generation) is a schema language for XML—a RELAX NG schema specifies a pattern for the structure and content of an XML document. A RELAX NG schema is itself an XML document but RELAX NG also ...
or
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 constrai ...
.
; 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.
Versions
Schematron was invented by
Rick Jelliffe while at
Academia Sinica
Academia Sinica (AS, ; zh, t=中央研究院) is the national academy of the Taiwan, Republic of China. It is headquartered in Nangang District, Taipei, Nangang, Taipei.
Founded in Nanjing, the academy supports research activities in mathemat ...
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.
(2002): This version was the base of ISO Schematron and obsoleted by it.
(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.
Schematron 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:2020).
This standard is currently not listed on th
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
Sample rule
Schematron rules can be created using a standard XML editor or
XForms
XForms is an XML format used for collecting inputs from web forms. XForms was designed to be the next generation of HTML / XHTML forms, but is generic enough that it can also be used in a standalone manner or with presentation languages other tha ...
application. The following is a sample schema:
Date rules
ContractDate should be
in the past because future contracts are not allowed.
This rule checks to make sure that the 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.
Implementation
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
XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text, or XSL Formatting Objects. These formats c ...
stylesheets, these can themselves be used in XML Pipelines which support XSLT transformation. An
Apache Ant
Apache Ant is a software tool for automating software build processes for Java applications which originated from the Apache Tomcat project in early 2000 as a replacement for the Make build tool of Unix. It is similar to Make, but is implement ...
task can be used to convert Schematron rules into XSLT files.
There exists also native Schematron implementation, like the Java implementation from Innovimax/
INRIA
The National Institute for Research in Digital Science and Technology (Inria) () is a French national research institution focusing on computer science and applied mathematics.
It was created under the name French Institute for Research in Comp ...
QuiXSchematron that also do
streaming
Streaming media refers to multimedia delivered through a network for playback using a media player. Media is transferred in a ''stream'' of packets from a server to a client and is rendered in real-time; this contrasts with file downl ...
.
See also
*
XML Schema Language comparison - Comparison to other XML Schema languages.
*
Service Modeling Language - Service Modeling Language uses Schematron.
*
Document Schema Definition Languages
References
External links
Academia Sinica Computing Centre's Schematron Home PageA book on Schematron (in German)Schematron online tutorial and reference
{{Authority control
Data modeling languages
ISO/IEC standards
XML
XML-based programming languages
XML-based standards