W3C home > Mailing lists > Public > xmlschema-dev@w3.org > May 2003

Re: Meaning of xs:pattern in xs:boolean

From: Jeni Tennison <jeni@jenitennison.com>
Date: Fri, 30 May 2003 09:33:33 +0100
Message-ID: <3662808227.20030530093333@jenitennison.com>
To: "Wiedmann, Jochen" <jochen.wiedmann@softwareag.com>
CC: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>

Hi Jochen,

> I see that the boolean type is constrained by xs:pattern. As there
> are only four possible values, I have the impression that patterns
> do not make much sense for booleans, unless the meaning is: "true",
> if the pattern matches, and "false" otherwise. Is that the case?

The pattern facet constrains the lexical representation of the data
type within an XML document. An example with xs:boolean would be to
create a data type that could only use the lexical values "true" and
"false" and not the lexical values "1" and "0":

<xs:simpleType name="true-or-false">
  <xs:restriction base="xs:boolean">
    <xs:pattern value="true" />
    <xs:pattern value="false" />
  </xs:restriction>
</xs:simpleType>

If the <foo> element were declared as being of type true-or-false then
the following would be valid:

  <foo>true</foo>
  <foo>false</foo>

while the following would be invalid:

  <foo>1</foo>
  <foo>0</foo>
  <foo>rubbish</foo>

Likewise, you could restrict xs:boolean to only allow the lexical
representations "1" and "0" or, if you were feeling particularly
contrary, "true" and "0" or "1" and "false".

(In contrast, the enumeration facet wouldn't make any sense on
xs:boolean because all you could say is "this boolean must have the
value true" or "this boolean must have the value false", and if you
want to do that you should probably fix the value of the
attribute/element instead. That's why the enumeration facet isn't
allowed with xs:boolean.)

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Friday, 30 May 2003 04:33:46 GMT

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