Home arrow XML arrow Page 5 - More Schematron Features
XML

More Schematron Features


In my last two articles, I covered the basics of Schematron—enough of it to create a basic schema with assertions, rules and patterns. However, there is more to Schematron than was covered in those articles, and some of Schematron's other features are very useful and worth mentioning. In this article, we'll take a look at more of Schematron's features, delving deeper into the Schematron schema language.

Author Info:
By: Peyton McCullough
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
January 22, 2009
TABLE OF CONTENTS:
  1. · More Schematron Features
  2. · More on assertions
  3. · Declaring variables with the let element
  4. · Phases
  5. · Diagnostics

print this article
SEARCH DEVARTICLES

More Schematron Features - Diagnostics
(Page 5 of 5 )

Since assertions in Schematron are made using plain language, if a document doesn't validate, it's often easy to figure out what's wrong and to fix it. However, sometimes, the assertion itself doesn't provide enough information. The user may need to know more information about the problem in order to fix it. This kind of information should not be placed in an assertion. Rather, it should be placed in a separate diagnostics section.

The diagnostics section contains diagnostic elements that give more information about a problem, such as what was expected and how to go about fixing the problem. Each diagnostic must be given a unique identifier using the id attribute. Assertions can then point to the relevant diagnostic element, and if there's a problem, then the contents of that diagnostic will be made available to the user.


Diagnostics are placed in a diagnostics element, which must be a child of the schema element:


<diagnostics>
    ...
</diagnostics>


As mentioned, a diagnostic element must have a unique identifier set using the id attribute. Within the element is the diagnostic message. Let's go back to our earlier scenario of checking the domain name of an e-mail address. We can create a diagnostic for the length assertion. Recall that a domain name can only be 253 characters long. We can convey this information in the diagnostic:


<diagnostic id="domain_length">
    A full domain name can only be 253 characters long. 
The supplied domain name exceeded this amount.
</diagnostic>


Next, the relevant report needs to point to the diagnostic using the diagnostics attribute:


<report test="string-length($domain)>253" diagnostics="domain_length">The domain is too long.</report>


Now, if the domain part of an e-mail address is too long, then the diagnostic information is available to help the user out, in addition to the report itself.

It's still possible to give even more information, though. In addition to telling the user what value was expected (a domain name of 253 characters or less), it's possible to tell the user what value was given. In this situation, we could tell the user the length of the supplied domain name. This is possible using the value-of element, which substitutes the result of an expression contained in its select attribute. Below, we modify the diagnostic to tell the user exactly how long the supplied domain is:


<diagnostic id="domain_length">
    A full domain name can only be 253 characters long. 
The supplied domain name was 
<value-of select="string-length($domain)"/> characters long.
</diagnostic>


This will provide the user with even more help in solving any problems, yet it didn't require much work on our part. This same observation—that a lot was done with a little bit of work—applies to all of the concepts covered in this article and to Schematron in general. Schematron offers a remarkable amount of power and flexibility without introducing complicated concepts or methods. Everything is rather straightforward and elegant, just as it should be.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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