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

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
xsd conditional min
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"
elementFormDefault="qualified">
 <xs:element name="Test">
  <xs:annotation>
   <xs:appinfo>
    <pattern name="min less than or equal to max"
xmlns="http://www.ascc.net/xml/schematron">
     <rule context="Test">
      <assert test="@min &lt;= @max">The min attribute must be less than or equal
to the max attribute.</assert>
     </rule>
    </pattern>
   </xs:appinfo>
  </xs:annotation>
  <xs:complexType>
   <xs:attribute name="min" type="xs:integer" use="required"/>
   <xs:attribute name="max" type="xs:integer" use="required"/>
  </xs:complexType>
 </xs:element>
</xs:schema>

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].

Cheers,
/Eddie

[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 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
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-2007 All Rights Reserved.