Home arrow XML arrow Page 3 - Schematron Patterns and Validation
XML

Schematron Patterns and Validation


In the last article, we grouped assertions into rules. As you know, each rule has its own context that it acts upon. So, grouping assertions into a rule provides a way to organize assertions that apply to the same elements. In this article, we'll start by explaining patterns, which takes organization to a new level.

Author Info:
By: Peyton McCullough
Rating: 4 stars4 stars4 stars4 stars4 stars / 7
January 14, 2009
TABLE OF CONTENTS:
  1. · Schematron Patterns and Validation
  2. · Abstract Patterns
  3. · Validation
  4. · Conclusion

print this article
SEARCH DEVARTICLES

Schematron Patterns and Validation - Validation
(Page 3 of 4 )

Now you know almost enough Schematron to create a functional schema and then validate an XML document against it. The only thing left to do is to wrap the schema definition inside of a schema element, which is the root element of a Schematron schema definition. This step is easy:


<schema xmlns="http://purl.oclc.org/dsdl/schematron">
  ...
</schema>


Now the schema is ready for use.

In order to validate an XML document against a schema, you need a Schematron implementation. There are several implementations of Schematron available, operating in different ways. The simplest implementation is the “skeleton” implementation; it can be used by itself or as a reference for other validators to be built upon. It's written using XSLT, so all that you need to use it is an XSLT transformer. Other validators built upon the skeleton implementation are listed on the Schematron Web site:

http://www.schematron.com/validators.html

One of the simplest validators to start with is Schematron Text. It will validate an XML document against a schema, and then display the result in plain text. So, it's suitable to use in a command line environment. All you need to do is download the XSL file and make sure you have an XSLT transformer. Saxon is a good transformer and is easy to use at the command line. It's available as a JAR or as a .NET assembly:

http://saxon.sourceforge.net/

Note that there are two versions of Saxon: an open source version (Saxon-B) and a commercial version (Saxon-SA). The open source version will work just fine for our purposes. If you're going to use Saxon, then download the open source version unless you intend to obtain a license for the commercial version from Saxonica.

Validation using an XSLT implementation is simple. First, the schema needs to be “compiled” with the XSLT file. A new XSLT file will be generated in the process. Here's how this would be done using Schematron Text, Saxon (the JAR version), and a schema named myschema.sch (.sch is the typical extension for a Schematron schema definition):

java -jar saxon9.jar -o myschema-compiled.xsl myschema.sch iso_schematron_text.xsl

This will create the file myschema-compiled.xsl which can then be used to validate an XML document against the schema. Here's how you would validate a document called doc.xml using the schema:

java -jar saxon9.jar doc.xml myschema-compiled.xsl

Each assertion will be tested, and if an assertion is unmet, then the assertion will be displayed in the console, along with the path to the appropriate node. Note that the skeleton implementation and Schematron Text will not terminate if the validation fails. Instead, validation of the document will continue.


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