Re: restriction query - XML Schema

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

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

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

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