AndiDog
AndiDog

Reputation: 70148

XSD string pattern independent of leading/trailing space

I have a XSD simple type that should match UUIDs:

<simpleType name="UuidT">
    <restriction base="string">
        <pattern value="[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}" />
    </restriction>
</simpleType>

It correctly matches the following content:

<!-- valid -->
<Uuid>12345678-1234-5678-9012-123456789012</Uuid>

But it doesn't match content that contains excess whitespace:

<!-- not valid -->
<Uuid>
    2de25a81-b117-4b2a-b910-50f0878884f7
</Uuid>

Sure, I could add \s* to both sides of the regex, but isn't there a simpler solution in XSD?

Upvotes: 1

Views: 855

Answers (2)

John Saunders
John Saunders

Reputation: 161781

Try restriction base="xs:token".

Upvotes: 2

Kobi
Kobi

Reputation: 138037

According to this, you should define

<xs:whiteSpace value="collapse"/>

(possibly without the namespace)

Upvotes: 2

Related Questions