W3C home > Mailing lists > Public > xmlschema-dev@w3.org > November 2001

Re: min/maxOccurs, can be expressed in a schema?

From: Eddie Robertsson <eddie@allette.com.au>
Date: Wed, 07 Nov 2001 09:51:45 +1100
Message-ID: <3BE86981.CF450907@allette.com.au>
To: Joan Pujol <joan.pujol@ima.udg.es>
CC: xmlschema-dev@w3.org
Hi Joan,

> One question, this type of restrictions can be done with schemas?
> Or must be done in a post-schema validation?
> For example if I declare two attributes named min and max, can I control that
> max<=min with a schema?

Unfortunately you can't do these conditional relationships with the current
version of W3C XML Schema but it probably will be supported in the next version.
However, in the mean time we have to use other means to achieve these kinds of
constraints and one way to do it is to combine Schematron with W3C XML Schema.
What you do is to include a Schematron rule in the xs:appinfo element of your XML
Schema and for your constraint above it could look like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 <xs:element name="Test">
    <pattern name="min less than or equal to max"
     <rule context="Test">
      <assert test="@min &lt;= @max">The min attribute must be less than or equal
to the max attribute.</assert>
   <xs:attribute name="min" type="xs:integer" use="required"/>
   <xs:attribute name="max" type="xs:integer" use="required"/>

The Schematron Validator from Topologi [1] can validate XML Schemas and
Schematron as well as provide validation results from embedded Schematron rules
like the above example. For more information about Schematron see [2] and more
information about how to extend XML Schemas can be found at [3].


[1] www.topologi.com
[2] http://www.ascc.net/xml/resource/schematron/
[3] http://www.xfront.com/BestPracticesHomepage.html (see Extending XML Schemas)
Received on Tuesday, 6 November 2001 17:45:00 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:14:55 UTC