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

Re: extending enumeration ?

From: Stefan Wachter <Stefan.Wachter@gmx.de>
Date: Mon, 26 Aug 2002 08:38:21 +0200 (MEST)
To: Jeni Tennison <jeni@jenitennison.com>; xmlschema-dev@w3.org
Message-ID: <3118.1030343901@www43.gmx.net>

Hi Jeni,

is there also an ordering between the member types that are referenced and
the member types that are defined as anonymous inner types when deciding which
member type to use to create an instance?

I did not find a section in the spec. where an ordering of the member types
is mentioned.

Thanks,
--Stefan


> 
> 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 Monday, 26 August 2002 02:38:57 GMT

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