views:

37

answers:

2

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?

+2  A: 

According to this, you should define

<xs:whiteSpace value="collapse"/>

(possibly without the namespace)

Kobi
This works, but that replaces all whitespace by spaces, no matter whether is leading/trailing or in the middle of the content. Might not always be what I want (but it's okay in this case).
AndiDog
+2  A: 

Try restriction base="xs:token".

John Saunders
The W3C tutorials (http://www.w3schools.com/Schema/schema_dtypes_string.asp) say that it does the same as `<whiteSpace value="collapse"/>`, i.e. replacing all whitespace with spaces and multiple whitespace with single space. Seems like there's no exact solution to my problem, but token will work.
AndiDog