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

Re: how do I express this content model?

From: Eddie Robertsson <eddie@allette.com.au>
Date: Mon, 03 Sep 2001 09:56:26 +1000
Message-ID: <3B92C72A.511ABB1E@allette.com.au>
To: Kevin Burges <xmldude@burieddreams.com>
CC: xmlschema-dev@w3.org
Hi Kevin,

> Lets say I have <column> element. I want to have a content model like
> this:
>             ___ name (optional)
>            /
> column  ------- field OR formula (mandatory)
>            \
>             \-- width (optional)
> Where the children can appear in any order.
> what I would like is:
>                   __ name (minOccurs=0)
>                  /
>                 /                         __ field (minOccurs=1)
> column --[ALL]-----[CHOICE minOccurs=1]--|__ formula (minOccurs=1)
>                 \
>                  \__ width (minOccurs=0)
> But it appears I cannot have a CHOICE section inside the ALL. Can this
> not be done?

Unfortunately you can't do this with the current version of W3C XML
Schema. I think someone already made wish for loosening the constraints on
the xs:all construct for the next version of XML Schema but I'm not sure
anything will be one about it. 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" attributeFormDefault="unqualified">
 <xs:element name="column">
    <pattern name="Extended_all"
     <rule context="column">
      <assert test="not(field and formula)">You can have either field or
formula but not both.</assert>
    <xs:element name="name" type="xs:string" minOccurs="0"/>
    <xs:element name="field" type="xs:string" minOccurs="0"/>
    <xs:element name="formula" type="xs:string" minOccurs="0"/>
    <xs:element name="width" type="xs:string" minOccurs="0"/>

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


[1] www.topologi.com
[2] http://www.ascc.net/xml/resource/schematron/
[3] http://www.xfront.com/BestPracticesHomepage.html (see Extending XML
Received on Tuesday, 2 October 2001 19:50:01 UTC

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