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

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>

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" />

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" />

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

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.



Jeni Tennison
Received on Thursday, 22 August 2002 09:50:40 UTC

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