Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

A hands-on introduction to Schematron

Directly express rules without creating a whole grammatical infrastructure

Uche Ogbuji, Consultant and Co-Founder, Fourthought
Uche Ogbuji is a consultant and co-founder of Fourthought Inc., a software vendor and consultancy specializing in XML solutions for enterprise knowledge management. Fourthought develops 4Suite, an open source platform for XML, RDF, and knowledge-management applications. Mr. Ogbuji is also a lead developer of the Versa RDF query language. He is a computer engineer and writer born in Nigeria, living and working in Boulder, Colorado, USA. You can contact Mr. Ogbuji at uche.ogbuji@fourthought.com.

Summary:  Meet Schematron, a schema language that allows you to directly express rules without creating a whole grammatical infrastructure. Schematron is useful whenever you wish to apply and check against rules for the contents of XML documents. Schematron is extraordinarily flexible in the variety of rules you can express, and it's even more expressive than other schema languages such as DTD, W3C XML Schema (WXS) and RELAX NG. In this tutorial, author Uche Ogbuji uses detailed examples to illustrate Schematron's use, and offers recipes for common schema needs.

Date:  02 Sep 2004
Level:  Intermediate PDF:  A4 and Letter (87 KB | 24 pages)Get Adobe® Reader®

Activity:  29817 views
Comments:  

Tutorial introduction

Who should take this tutorial?

Most developers of XML-based applications want a way to be sure that all XML instances follow certain rules. For this, many people immediately turn to schema languages such as DTD, W3C XML Schema (WXS), and RELAX NG. The best solution might be to apply simple rules to XML instances. Schematron is a language that allows you to directly express rules without creating a whole grammatical infrastructure.

All developers of XML vocabularies and software that uses XML in any significant way should learn Schematron, and this tutorial is a great way to get started. Even if you already use schema languages such as RELAX NG and WXS, you may need to augment them with Schematron rules, which are more general and more flexible.

Prerequisites

This tutorial assumes knowledge of XML, XML Namespaces, and XPath. If you aren't familiar with these technologies, I recommend you first take these developerWorks tutorials:

It is helpful to have some knowledge of XSLT -- at least the basics of how to declare and apply templates. If you aren't familiar with XSLT, I recommend that you first take the tutorial "Create multi-purpose Web content with XSLT".

I highly recommend that you follow along with the examples (see Download to download it). To do so you will need to use a Schematron tool of some sort. While developing these examples I used the Scimitar implementation of ISO Schematron. Other tools are available from the Schematron resource page (see Resources).


About the Schematron examples in this tutorial

In this tutorial you will see many examples of Schematron files, and XML documents that illustrate the sorts of patterns the schemas are looking for. All the files used in this tutorial are in the zip file, x-schematron-files.zip (see Download). In this package, all files start with a prefix indicating the tutorial section that covers them and the order of examples within the section. For example, files from the first example in the third section are named starting with "eg3_1".

Files ending with ".sch" are Schematron schema files, and files ending in ".xml" are sample XML documents to be processed with the schema of the same prefix. Some, such as eg3_1_good1.xml, are valid against the corresponding schema; some, such as eg3_1_bad1.xml, are not valid. A few, such as eg4_1_1.xml, correspond to Schematron files that are not meant for validation at all, but rather for reporting.

I do take care to further list the example files in each panel featuring an example. If you follow along with the tutorial you should be able to locate and experiment with the examples easily enough.

1 of 9 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML
ArticleID=138368
TutorialTitle=A hands-on introduction to Schematron
publish-date=09022004
author1-email=uche.ogbuji@fourthought.com
author1-email-cc=