[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Restrictions on booleans

From: Jeni Tennison <jeni@jenitennison.com>
Date: Thu, 22 Aug 2002 14:50:38 +0100
Message-ID: <141865257644.20020822145038@jenitennison.com>
To: xmlschema-dev@w3.org, Robin Berjon <robin.berjon@expway.fr>
xml xs boolean permitted values

Hi Robin,

> xsd:boolean accepts the values "true", "false", "1", and "0".

That's right -- those are the legal "lexical representations" of
xs:boolean. But xs:boolean only has two values, true and false ("true"
and "1" are lexical representations of the value true; "false" and "0"
are lexical representations of the value false).

> My reading of the spec would seem to indicate that the following is
> legal:
>
> <restriction base='boolean'>
>    <pattern value='true|false'/>
> </restriction>
>
> in order to model a language that has boolean types but only those two 
> strings to flag truth (0 and 1 being illegal).

Quite right.

> My questions are: have I understood the spec correctly, and if so
> does that make much sense? It feels a bit strange having to use a
> pattern here, any reason why the equivalent enumeration isn't
> allowed?

I'm not sure why the enumeration isn't allowed at all, but note that
if it were you can only constrain the *values* that are permitted
through enumeration. If you did:

  <xs:restriction base="xs:boolean">
    <xs:enumeration value="true" />
    <xs:enumeration value="false" />
  </xs:restriction>

you'd be saying "a boolean value, but only the *values* true or
false", not "a boolean value, but only the *lexical representations*
"true" or "false"". In other words, using an enumeration wouldn't
enable you to say that you wanted to permit "true" and "false" but not
"1" and "0".

It's just the same as with numbers, you can enumerate:

  <xs:restriction base="xs:decimal">
    <xs:enumeration value="5" />
    <xs:enumeration value="10" />
  </xs:restriction>

but that doesn't stop someone using "00005" or "10.0000" in the XML
document.

If enumeration were allowed for xs:boolean, the only use would be to
say that you only wanted to allow true values ("true" or "1") or only
wanted to allows false values ("false" or "0"). I imagine that this is
why enumerations aren't allowed for booleans -- it's not something
that you're actually likely to want to do.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Thursday, 22 August 2002 09:50:40 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.