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

Re: Extending a schema by adding choices

From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Date: 24 Aug 2001 11:35:17 +0100
To: Daniel Flippance <DFlippance@mpsbc.com>
Cc: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>
Message-ID: <f5b3d6hg2ze.fsf@cogsci.ed.ac.uk>
Daniel Flippance <DFlippance@mpsbc.com> writes:

> We are trying to define 2 schemas, one which allows 2 options in an
> xsd:choice, and one which extends this and allows 3 options.
> If one schema defines 2 choices of elements, can this list of choices be
> extended in a deriving schema?

No.  The invariant for extension is that any instance of the derived
type has an instance of the base type as a prefix.  Extending always
operates to allow the _addition_ of material.

To get the effect you want, use a substitution group, e.g.

<xsd:complexType name="Contact">
  <xsd:complexContent>
    <xsd:sequence>
      <xsd:element ref="contact"/>
    </xsd:sequence>
  </xsd:complexContent>
</xsd:complexType>

<xsd:element name="contact" abstract="true" type="xsd:string"/>
<xsd:element name="Telephone" substitionGroup="contact" />
<xsd:element name="Fax" substitionGroup="contact" />

Then a derived schema can add

<xsd:element name="EMail" substitionGroup="contact" />

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2001, part-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/
Received on Friday, 24 August 2001 06:34:55 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:23 GMT