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

Re: is the best/only way to restrict the values of an attribute

From: Jeni Tennison <jeni@jenitennison.com>
Date: Mon, 15 Apr 2002 09:49:12 +0100
Message-ID: <1501127730610.20020415094912@jenitennison.com>
To: "Randy Eastwood" <sunmesa@cox.net>
CC: "W3C XSchema List" <xmlschema-dev@w3.org>
Hi Randy,

> Can someone tell me if this is the best/only way to restrict the
> values of an attribute? I only have one attribute named "allow" and
> I want it to be either YES or NO.

As well as nesting the simple type of the attribute, as Dare showed
you, the other change you could make would be to restrict from
xs:token instead of xs:string:

<xs:simpleType name="allowValues">
 <xs:restriction base="xs:token">
  <xs:enumeration value="YES"/>
  <xs:enumeration value="NO"/>

The only difference between the two is how whitespace is treated. When
you restrict from xs:string, the value of the attribute has to
literally be the enumerated value that you specify, so for example:

  <LACAllowTIRUpload allow="YES" />

would be valid but:

  <LACAllowTIRUpload allow=" YES " />

would be invalid. If you restrict from xs:token, then both are valid.
The reason I suggest this is because other XML Schema simple types
treat whitespace like xs:token rather than xs:string. For example:

  <date xsi:type="xs:date"> 2002-04-15 </date>

is valid because the whitespace is stripped during validation.



Jeni Tennison
Received on Monday, 15 April 2002 05:10:05 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:56 UTC