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"/>
 </xs:restriction>
</xs:simpleType>


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.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Monday, 15 April 2002 05:10:05 GMT

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