Re: combining enumeration and pattern

Hi Simon,

> Re: Re-using XSD schema-for-schemasIn simpleType derivation-by
> restriction, is it legal to apply both enumeration and pattern
> constraints in the same derivation step?

Yes, that's fine, but it means something different from what I think
you think it means. The example you give:

> <simpleType name="DrillCodeType">
>     <restriction base="string">
>       <enumeration value="RAB"/>
>       <enumeration value="RC"/>
>       <enumeration value="DD"/>
>       <enumeration value="DD-HQ"/>
>       <enumeration value="DD-NQ"/>
>       <pattern value="other:\w{2,}"/>
>     </restriction>
>   </simpleType>

means that values of the DrillCodeType must be one of 'RAB', 'RC',
'DD', 'DD-HQ' or 'DD-NQ' *and* must match the regular expression
'other:\w{2,}'. Since none of the enumerated values match the regular
expression, you end up with a type with no legal values (which isn't
good news).

If you want to say that DrillCodeType can be *either* one of the
enumerated values *or* match the pattern, then it needs to be a union
type:

<simpleType name="DrillCodeType">
  <union>
    <simpleType>
      <restriction base="string">
        <enumeration value="RAB"/>
        <enumeration value="RC"/>
        <enumeration value="DD"/>
        <enumeration value="DD-HQ"/>
        <enumeration value="DD-NQ"/>
      </restriction>
    </simpleType>
    <simpleType>
      <restriction base="string">
        <pattern value="other:\w{2,}"/>
      </restriction>
    </simpleType>
  </restriction>
</simpleType>

You could alternatively create a type that allowed these values using
only pattern facets:

<simpleType name="DrillCodeType">
  <restriction base="string">
    <pattern value="RAB"/>
    <pattern value="RC"/>
    <pattern value="DD"/>
    <pattern value="DD-HQ"/>
    <pattern value="DD-NQ"/>
    <pattern value="other:\w{2,}"/>
  </restriction>
</simpleType>

but if you were using this schema with applications that, for example,
prompt the user with the allowed values, then it's better to use
enumerated values.

> If yes, is it still OK if the pattern used for a restiction of
> simpleContent in a complexType definition.

I'm not sure what you're asking here. You can use the pattern facet
however the simple type that you're defining is used.

Cheers,

Jeni

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

Received on Monday, 30 June 2003 04:52:28 UTC