W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2003

Re: Extension and all-group

From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Date: 04 Feb 2003 08:42:07 +0000
To: "Krautbauer, Bruce" <bruce.krautbauer@medtronic.com>
Cc: <xmlschema-dev@w3.org>
Message-ID: <f5b3cn4bfog.fsf@erasmus.inf.ed.ac.uk>

"Krautbauer, Bruce" <bruce.krautbauer@medtronic.com> writes:

> Hi, I'm the one that started this question on
> microsoft.public.dotnet.xml.  I appreciate Oleg posting it over for
> me and after reading the responses I'm confident this is a bad
> schema.  I'm wondering if anyone has a suggestion on how to go about
> specifying this sort of structure properly.  What we want is a base
> type that consists of elements, none or any of which that can be
> specified in any order, and a type derived from the base type that
> adds elements, which must be specified but can appear in any order.
> If this is beyond XML Schema does anyone have any ideas for an
> alternative approach I can present to the team that would accomplish
> something close?

If you mean exactly what you say above, then there is no XML Schema
facility that does what you want.  There is a principled reason for
this -- what you describe would allow an instance of the derived type
definition to bear virtually no relation to instances of the base type
-- that's not a derivation as XML Schema defines it.

If you are prepared to compromise a bit, it's easy to define a type
which allows variable content, and extend that content in another
schema.  The Substitution Group facility is designed for this purpose.
Simply declare the original type to allow any number of an abstract
element, then have your other elements identify that one as their
substitution group head.  Then adding further elements at a later time
is easy.

For example


. . .
<xs:complexType name="orig">
 <xs:sequence minOccurs="0" maxOccurs="unbounded">
  <xs:element ref="top"/>

<xs:element name="top" abstract="true"/>

<xs:element name="a1" substitutionGroupHead="top" type="..."/>
<xs:element name="a2" substitutionGroupHead="top" type="..."/>
<xs:element name="a3" substitutionGroupHead="top" type="..."/>


<xs:include schemaLocation="a.xsd"/>
. . .

<xs:element name="foo" type="orig"/>

<xs:element name="b1" substitutionGroupHead="top" type="..."/>
<xs:element name="b2" substitutionGroupHead="top" type="..."/>
. . .

Any of a1, a2, a3, b1, b2 can appear in the content of foo.  If they
all share a type or a base type, that can and should be used as the
type of the 'top' element.

Hope this helps

  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
                      Half-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/
 [mail really from me _always_ has this .sig -- mail without it is forged spam]
Received on Tuesday, 4 February 2003 03:41:59 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:09 UTC