Schematron briefly and succinctly

(Excerpt from "Schematron - Effiziente Business Rules für XML-Dokumente", ["Schematron - efficient business rules for XML documents"]
chapter 5)

XPath offers a wide range of possibilities to analyse XML documents and to check them by means of different criteria. The XPath constructs are embedded into the Schematron language in order to draw attention to errors and discrepancies and to respond to them with significant answers. These sites provide an introdution to Schematron and a detailed explanation for the functionality of the respective constructs.

After a detailed reading of this Schematron introduction, you will be able to analyse XML documents according to the ISO Standard Schematron, to understand the functionality as well as to generate practical schemata.
Starting with a brief overview of the historical development, the functionality of the most important Schematron constructions is explained by using the Noah's Ark example instance.

XML example instance – the XML serialisation of Noah's Ark:

<?xml version="1.0" encoding="UTF-8"?>
<ark xmlns="http://www.schematron.info/ark" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.schematron.info/ark ark.xsd">
  <load>
    <room>
      <animal sex="female" carnivore="no">
        <species>zebra</species>
        <weight>200</weight>
        <age>12</age>
      </animal>
      <animal sex="male" carnivore="no">
        <species>zebra</species>
        <weight>250</weight>
        <age>13</age>
      </animal>
    </room>
    <room>
      <animal sex="female" carnivore="yes">
        <species>lion</species>
        <weight>200</weight>
        <age>23</age>
      </animal>
      <animal sex="male" carnivore="yes">
        <species>lion</species>
        <weight>180</weight>
        <age>30</age>
      </animal>
    </room>
    <room>
      <animal sex="female" carnivore="no">
        <species>elephant</species>
        <weight>10000</weight>
        <age>20</age>
      </animal>
      <animal sex="male" carnivore="no">
        <species>elephant</species>
        <weight>15000</weight>
        <age>40</age>
      </animal>
    </room>
  </load>
  <maxReproductionAge>
    <animal_species>
      <name>elephant</name>
      <male>80</male>
      <female>30</female>
    </animal_species>
    <animal_species>
      <name>lion</name>
      <male>30</male>
      <female>15</female>
    </animal_species>
    <animal_species>
      <name>zebra</name>
      <male>30</male>
      <female>20</female>
    </animal_species>
  </maxReproductionAge>
  <loadingCapacity>44000</loadingCapacity>
</ark>

The conditions for a "good" coexistence on the Ark are recorded in the following XML Schema:

Graphical depiction of the Ark schema:

Graphical depiction of the Ark schema

The XML Schema file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.schematron.info/ark" xmlns="http://www.schematron.info/ark" elementFormDefault="qualified">
  <xs:element name="age" type="xs:positiveInteger"/>
  <xs:element name="ark">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="load"/>
        <xs:element ref="maxReproductionAge"/>
        <xs:element ref="loadingCapacity"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="species" type="xs:string"/>
  <xs:element name="weight" type="xs:positiveInteger"/>
  <xs:element name="load">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="room" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="maxReproductionAge">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="animal_species" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="male" type="xs:positiveInteger"/>
  <xs:element name="name" type="xs:string"/>
  <xs:element name="loadingCapacity" type="xs:positiveInteger"/>
  <xs:element name="animal">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="species"/>
        <xs:element ref="weight"/>
        <xs:element ref="age"/>
      </xs:sequence>
      <xs:attribute name="sex" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:enumeration value="male"/>
            <xs:enumeration value="female"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="carnivore" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:enumeration value="yes"/>
            <xs:enumeration value="no"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>
  <xs:element name="animal_species">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="name"/>
        <xs:element ref="male"/>
        <xs:element ref="female"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="room">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="animal" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="female" type="xs:positiveInteger"/>
</xs:schema>
  next >>

 

 

 


Copyright © dpunkt.verlag GmbH 2011
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "Schematron - Effiziente Business Rules für XML-Dokumente" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, fon 06221-14830, fax 06221-148399, hallo(at)dpunkt.de