Re: Whitespace and patterns

Hi Michael,

> If I have the following type definition
>
>   <xsd:simpleType name="Fred">
>     <xsd:restriction base="xsd:string">
>       <xsd:pattern value="[\p{L}\p{N}\s]{1,30}"/>
>     </xsd:restriction>
>   </xsd:simpleType>
>   <xsd:element name="Fred" type=""Fred"/>
>
> Would a single space be legitimate content for Fred?, i.e.
>
> <Fred> </Fred>
>
> What I am trying to say is that any mixture of letters, numbers and
> whitespace from 1to 30 characters is allowed.
>
> XMLSpy says "the value does not match facet" but I'm struggling to
> see why.

Yes, it should be OK. Xerces C++ validates it OK.

If you just want to constrain the length of the string, it's a better
idea to use the min/max facets instead, I think:

  <xsd:simpleType name="Fred">
    <xsd:restriction base="xsd:string">
      <xsd:minLength value="1" />
      <xsd:maxLength value="30" />
    </xsd:restriction>
  </xsd:simpleType>

Or you could try using:

  (\p{L}|\p{N}|\s)+

instead - see if XML Spy can manage that any better.
  
Cheers,

Jeni

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

Received on Wednesday, 16 January 2002 07:19:32 UTC