[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Datatypes in Schematron (was Re: Namespaces,W3C XML Schema (was Re: ANN:

  • From: Rick Jelliffe <ricko@a...>
  • To: Xml-Dev <xml-dev@l...>
  • Date: Thu, 23 Aug 2001 13:54:19 +1000

schematron datatypes
> >Elliotte Rusty Harold wrote:
 
> On the other hand, over the last three years as I've taught developers about DTDs, almost invariably the first question is "How do I say that an element contains an int?" and the second question is usually ""How do I say that an element contains a year since 1969?" or some variant thereof. 


In Schematron (untested), I think it would be something like this:

<schema xmlns="http://www.ascc.net/xml/schematron">
    <title>For Rusty's Inquiring Students</title>
    <p>This is an example of creating a datatype using Schematron's "abstract rules"
     and using them. </p>

    <pattern>
        
        <!-- Define an abstract rule on a data value (i.e. a type) for int  -->
        <rule abstract="true" id="int">
            <assert test="string-length(string-normalize(./text())) &gt; 0"
                >This element must contain a value.</assert>
            <assert test="number(./text())"
                >This element should contain an int. An int it a number.</assert>
            <assert test="floor(number(./text())) = ceiling(number(./text())) "
                >This element should contain an int. An int is a whole number.</assert>
            <assert test="number(./text()) &lt; 2147483647"
                >This element should contain an int. An int is less than 2^31-1.</assert>
            <assert test="number(./text()) &gt;= -2147483648"
                >This element should contain an int. An int is greater than -(2^31).</assert>
        </rule>

        <!-- Make the assertions -->
        <rule context="someElement" >
            <extends rule="int" />
        </rule>
        <rule context="someOtherElement">
            <extends rule="int" />
            <assert test="number(./text()) &gt; 1969"
                >This element should contain a year since 1969</assert>
        </rule>
   <pattern>
</schema>

Most other schema languages have built-in types. I guess that since people will
tend to evaluate schema languages using a check-box, they might put
"no datatyping" on Schematron, when really they mean no "built-in"
data types (apart from the XPath ones: number, string, boolean).  

With Schematron's approach, you can restrict a datatype
merely by providing extra assertions before or after the <extend>
element.  (You can over-ride datatype checking by catching the 
text in a previous rule: this is not type extension by allowing
type exceptions, I guess.) 

Cheers
Rick Jelliffe


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.