|
[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:
> >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())) > 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()) < 2147483647"
>This element should contain an int. An int is less than 2^31-1.</assert>
<assert test="number(./text()) >= -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()) > 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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|
|||||||||

Cart








