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

Re: restriction query - XML Schema

From: Jeni Tennison <jeni@jenitennison.com>
Date: Sat, 5 Apr 2003 15:56:08 +0100
Message-ID: <159-1866378881.20030405155608@jenitennison.com>
To: max.a.chappell@britishairways.com
CC: xmlschema-dev@w3.org

Hi Max,

> Are the following restrictions equally valid using XML Schema ?
> Restriction 1:
> <restriction base="xsd:string">
>       <pattern value="[A-Z]{1,9}"/>
> </restriction>
> Restriction 2:
> <restriction base="xsd:string">
>       <pattern value="[A-Z]"/>
>       <minLength value="1"/>
>       <maxLength value="9"/>
> </restriction>
> We often have non-technical people looking at our restrictions - for
> them Restriction 2 is easier to decipher, but is it 'legal' ?

The second one isn't quite what you want, because the pattern "[A-Z]"
will only match a single uppercase Latin character, and you want
between 1 and 9 of them. You can use a + (one or more) as in:

  <restriction base="xsd:string">
    <pattern value="[A-Z]+" />
    <minLength value="1" />
    <maxLength value="9" />

to do this, or use the <pattern> element from your first restriction
above to state explicitly in the *pattern* that it has to be between 1
and 9 characters long.

It's a good idea to use the non-lexical restrictions such as minLength
and maxLength because they are easier for tools to interpret than a
regular expression. For example, a tool can use a pattern to check a
value that's been entered, but it can't (without amazing
sophistication) use a pattern to prompt the user that they need to
enter a value "between 1 and 9 characters long".



Jeni Tennison
Received on Saturday, 5 April 2003 09:56:16 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:10 UTC