XML
  Home arrow XML arrow Page 5 - More Schematron Features
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

More Schematron Features
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-01-22

    Table of Contents:
  • More Schematron Features
  • More on assertions
  • Declaring variables with the let element
  • Phases
  • Diagnostics

  • 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


    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.

     

    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