Nerdio
Nerdio

Reputation: 1013

XML Validation in Netbeans with Regex

I have a string which looks like this...

 1-Jan-1970 01:00:00

This can start with a space (as this one does), or a digit if the data is double digit.

I have constructed a Regex in an XSD file to create a simple Timestamp type, this looks as follows;

<xs:simpleType name="Timestamp">
    <xs:restriction base="xs:token">
        <xs:pattern value="( [1-9]|[1-3][0-9])-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-[1-2][0-9][0-9][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]"/>
    </xs:restriction>
</xs:simpleType>

If I take this Regex, and the sample string given, and test in http://www.regextester.com/ it works.

However, if I try to validate some XML with it, it works for all dates that have tow digits, but not the one with the space (shown above)

Can anyone give me a steer on this one please?

Upvotes: 0

Views: 115

Answers (1)

C. M. Sperberg-McQueen
C. M. Sperberg-McQueen

Reputation: 25054

The token datatype excludes strings with leading and trailing whitespace from its lexical space.

Name xs:string (or some string-derived type which does not have the whitespace facet set to collapse), not xs:token, as the base type.

Upvotes: 1

Related Questions