- From: Jeni Tennison <jeni@jenitennison.com>
- Date: Sun, 25 Aug 2002 09:43:59 +0100
- 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 UTC