Schematron

from Wikipedia, the free encyclopedia

Schematron is a schema language for validating the content and structure of XML documents. The language is implemented using XSL transformations , so no special implementation is required, as is the case with most other document structure definition languages .

Schematron was developed in 1999 by Rick Jelliffe at the Academia Sinica Computing Center in Taipei , Taiwan. Since May 2006, Schematron 1.6 has been registered as the official ISO / IEC standard under the number 19757-3: 2006 (called ISO Schematron ).

Unlike DTD or XML schema , for example , Schematron is not used to define, but to validate content in XML documents. It does not use formal grammar , but finds patterns in the document structure. This makes it possible to define rules that would not be possible with traditional schema languages ​​based on grammars. Nevertheless, Schematron should primarily be understood as a supplement, not as a competitor, to other schema languages.

Possible areas of application include complex sets of rules that express dependencies between different parts of the document tree or that require dynamic calculations.

Concept and syntax

A Schematron schema essentially consists of an XML document with various validation rules, in each of which a context node is determined on which assurances and reports are formulated that are to be checked later.

The following example shows a Schematron 1.5 scheme:

<schema xmlns="http://www.ascc.net/xml/schematron">
  <title>A Schematron Mini-Schema for Schematron</title>
  <ns prefix="sch" uri="http://www.ascc.net/xml/schematron" />
  <pattern name="Schematron Basic Structure">
    <rule context="sch:schema">
      <assert test="sch:pattern">
	A schema contains patterns.
      </assert>
      <assert test="sch:pattern/sch:rule[@context]">
	A pattern is composed of rules.
	These rules should have context attributes.
      </assert>
      <assert test="sch:pattern/sch:rule/sch:assert[@test] or sch:pattern/sch:rule/sch:report[@test]">
	A rule is composed of assert and report statements.
	These rules should have a test attribute.
      </assert>
    </rule>
  </pattern>
</schema>

This mini-scheme, which enables a rudimentary test of a Schematron 1.5 scheme, consists of the following elements:

  • <schema xmlns="http://www.ascc.net/xml/schematron" > as the root element of the document,
  • an optional element <title>that describes the scheme,
  • Any number of <ns prefix="?*?*?" uri="?*?*?" />elements in which namespaces ( uri) and their prefixes ( prefix) are declared for use in XPath expressions,
  • <pattern name="?*?*?">as a container with description ( name) for several
  • <rule context="?*?*?">Elements, where is contextan XPath expression used to specify the environment in which the following two elements will run:
  • <assert test="?*?*?">to formulate an assurance together with an error text in case the testtest formulated in using XPath fails, or
  • (not used in the example) <report test="?*?*?">to formulate an assurance, together with a message text in case the test is successful.

At Schematron, you basically define the error or success messages yourself, which are then displayed as the result of the validation.

functionality

To execute the tests formulated in the scheme, it is necessary to use a Schematron implementation. One possible implementation is an XSL stylesheet, which in turn generates an XSL stylesheet from the given schema, with which the document to be checked is then transformed:

  1. MeinSchema.sch is the Schematron file with which the document EinDokument.xml is to be checked;
  2. MeinSchema.sch by means SchematronImplementation.xsl in MeinSchemaValidator.xsl converted, an XSL stylesheet that contains the necessary transformations to generate a report of the validation from the tests in the schema;
  3. MySchemaValidator.xsl is used to validate ADocument.xml by having the previously generated transformations output the successful <report>tests and the failed <assert>tests.

At the end, depending on the type of Schematron implementation used, there is a text or XML document that contains the results of the test (reports of successful <report>tests and failed <assert>tests). This result can e.g. B. be displayed to the user in a validator program.

The reference implementation is specifically designed in a modular manner, so that you can e.g. B. can use one of the standard text style sheets to generate a simple text output. The Schematron "core" is only designed to collect error and success messages. Your own extended stylesheet could then, for example, generate a self-defined XML format with error messages, which is first processed by software to determine whether errors have occurred in the validation before they are automatically recorded and displayed to the user.

See also

Web links