Home arrow XML arrow Page 2 - Using Schematron
XML

Using Schematron


If you use XML schema languages, you should consider Schematron. This powerful rule-based language lets you make distinctions which other languages find difficult or even impossible to handle. Best of all, you can use it in conjunction with other schema languages. This is the first part of a three-part series.

Author Info:
By: Peyton McCullough
Rating: 4 stars4 stars4 stars4 stars4 stars / 4
January 07, 2009
TABLE OF CONTENTS:
  1. · Using Schematron
  2. · Schematron, a rule-based schema language
  3. · Making assertions
  4. · Rules

print this article
SEARCH DEVARTICLES

Using Schematron - Schematron, a rule-based schema language
(Page 2 of 4 )

This is where Schematron comes in. Not all schema languages are grammar-based. Schematron is, instead, a rule-based language. In XML Schema, you define precisely the structure of an XML document, explicitly stating what is allowed in the document. By contrast, in Schematron, you define a set of patterns that will be looked for in an XML document, with each pattern containing one or more rules, and each rule containing assertions (we'll discuss exactly what all this means later).

You can use XPath expressions to define what to check for in a given XML document. This allows you to deal with much more than just the structure of an XML document. For example, in the XML document described earlier, we could have set constraints on the relationship between the age and eligible_to_vote elements. We could have said, "If the resident's age is below 18, then the resident should not be able to vote." Or, in the context of the document, "If the text of the age element is less than 18, then the text of the eligible_to_vote element should be 'no'." This is an example of an assertion.

However, there is nothing wrong with using XML Schema or any other grammar-based language, and Schematron does not seek to replace any such languages. In fact, rather than having to choose between Schematron and, for example, XML Schema, it's possible to use Schematron in conjunction with XML Schema. In the XML document we looked at earlier, we could have defined the structure with XML Schema, and we could have defined the relationship between age and eligibility to vote in Schematron. This makes for a very powerful and easy-to-use tool set. Note, however, that just because Schematron is powerful, it isn't difficult to work with. It's actually very simple, with only a few core elements defined.

It's not hard to validate a document against a Schematron schema definition, either. Several implementations exist, but the "skeleton" implementation uses XSLT. So a document can be validated using any XML transformer, such as Saxon. This also allows the output to be given in a variety of formats.


blog comments powered by Disqus
XML ARTICLES

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials