W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2002

Re: xs:all - why is minOccurs, maxOccurs restricted to "0" or "1" for child xs:element ?

From: Jeni Tennison <jeni@jenitennison.com>
Date: Mon, 1 Apr 2002 17:06:21 +0100
Message-ID: <1404023515.20020401170621@jenitennison.com>
To: Gary Cramblitt <garycramblitt@comcast.net>
CC: xmlschema-dev@w3.org
Hi Gary,

> If I'm not mistaken, this restriction on xs:all means it is
> impossible to write an XML-Schema for XHTML. Try to define the
> <body> element for example... There is a group working on modular
> definitions, supposedly to permit more flexibility as the XHTML spec
> evolves, but I also suspect because there is no other way to do it.
> I'd be happy if somebody could prove me wrong.

It's never *impossible* to write a schema for any markup language. For
example, you could just do:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

<xs:complexType name="anything">
    <xs:any namespace="##targetNamespace" />
<xs:element name="html" type="html:anything" />
<xs:element name="head" type="html:anything" />
<xs:element name="body" type="html:anything" />
... and so on ...

The schema isn't very *good* - it doesn't catch all the cases that
we'd consider invalid - but it's still a schema for XHTML.

You could say that it's impossible to write a *good* schema for XHTML,
but even then I don't think that's actually true. XHTML has a
perfectly good DTD, and any constraint that you can represent in a DTD
you can represent in an XML Schema schema. Taking the definition of
body, which you mentioned:

<!ELEMENT body %Block;>

You could create:

<xs:element name="body">
    <xs:group ref="html:Block" />

The definition of %Block; is:

<!ENTITY % Block "(%block; | form | %misc;)*">

Which can be translated to:

<xs:group name="Block">
  <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:group ref="html:block" />
    <xs:element ref="html:form" />
    <xs:group ref="html:misc" />

and so on.

There are certainly places in the original HTML DTD that used the SGML
& connector, I believe, for example the content of the head element,
which has to contain a title element, and can contain a maximum of 1
base element, as well as various other elements. This would be a good
place for xs:all, but it can't be used because of the restrictions on
it. But that doesn't mean we can't use the same solution as was used
for the XHTML DTD:

<!ELEMENT head (%head.misc;,
     ((title, %head.misc;, (base, %head.misc;)?) |
      (base, %head.misc;, (title, %head.misc;))))>

In schema, you could similarly do:

<xs:element name="head">
    <xs:group ref="html:head.misc"
              minOccurs="0" maxOccurs="unbounded" />
        <xs:element ref="html:title" />
        <xs:group ref="html:head.misc"
                  minOccurs="0" maxOccurs="unbounded" />
        <xs:sequence minOccurs="0">
          <xs:element ref="html:base" />
          <xs:group ref="html:head.misc"
                    minOccurs="0" maxOccurs="unbounded" />
        <xs:element ref="html:base" />
        <xs:group ref="html:head.misc"
                  minOccurs="0" maxOccurs="unbounded" />
        <xs:element ref="html:title" />
        <xs:group ref="html:head.misc"
                  minOccurs="0" maxOccurs="unbounded" />

Was there somewhere else in XHTML where you thought xs:all would be
useful if it wasn't for the constraints on what it can contain?



Jeni Tennison
Received on Monday, 1 April 2002 11:06:23 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:56 UTC