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

Re: extending enumeration ?

From: Jeni Tennison <jeni@jenitennison.com>
Date: Sun, 25 Aug 2002 09:43:59 +0100
Message-ID: <1661106053701.20020825094359@jenitennison.com>
To: xmlschema-dev@w3.org, "Evyatar Kafkafi" <Evyatar@orsus.com>

Hi Evyatar,

> In schema with restriction of enumeration:
>
>                 <xsd:simpleType>
>                         <xsd:restriction base="xsd:string">
>                                 <xsd:enumeration value="High"/>
>                                 <xsd:enumeration value="Medium"/>
>                         </xsd:restriction>
>                 </xsd:simpleType>
>
> If I want to state that the list is as specified but can also add
> other values, is there a way to state that ?

You can use a union of the enumerated type and the more general string
type. For example:

<xs:simpleType name="highOrMedium">
  <xs:restriction base="xs:string">
    <xs:enumeration value="High" />
    <xs:enumeration value="Medium" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="possibleValues">
  <xs:union memberTypes="highOrMedium xs:string" />
</xs:simpleType>

Note that a value of the type possibleValues will always be valid
(because every value is a valid string), which means that you won't be
able to catch errors such as people using 'Med' instead of 'Medium'.

The only real benefit of using the union type is that if you were to
use an application that gave you access to the type of the element or
attribute then you would see the type 'highOrMedium' if someone had
the value 'High' or 'Medium' and 'xs:string' at other times.

Also note that if you swapped 'highOrMedium' and 'xs:string' in the
memberTypes attribute that this wouldn't occur -- a value is of the
first type in a union type that it matches, so if they were swapped
then every value would be labelled a string.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Sunday, 25 August 2002 04:44:06 GMT

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