XML
  Home arrow XML arrow Page 3 - Schematron Patterns and Validation
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Schematron Patterns and Validation
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2009-01-14

    Table of Contents:
  • Schematron Patterns and Validation
  • Abstract Patterns
  • Validation
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    More XML Articles
    More By Peyton McCullough


     

    XML ARTICLES

    - 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
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek