BentCoder
BentCoder

Reputation: 12720

XSD validates wrong format of xs:date and xs:dateTime

When I set the year section like below (20512 or anything like this), XSD still validates XML.

Any idea.

Is this a flaw or do I have to use simpleType with given pattern?

Thanks

XSD

<xs:attribute name="date" type="xs:date" />

<xs:attribute name="timestamp" type="xs:dateTime" />

XML

<store date="20512-07-11" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="items.xsd">

<store timestamp="20512-07-11T21:50:16" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="items.xsd">

Upvotes: 4

Views: 26830

Answers (2)

Petru Gardea
Petru Gardea

Reputation: 21638

It is NOT flaw in your validator (btw, you should indicate which validator you're using). Other validators (mis)behave the way you seem to expect; for e.g., .NET would complain The value '20512-07-11' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:date' - The string '20512-07-11' is not a valid XsdDateTime value.

See this section of the XSD spec, section D3.3 which clearly states that your value is valid.

Upvotes: 4

Michael Kay
Michael Kay

Reputation: 163262

Sorry, but why do you consider 20512-07-11 to be an invalid date? Astronomers might be very keen to maintain data showing that an eclipse will occur on that date.

If you want to limit your dates to a particular range, e.g before the year 2100, then you should use a simpleType derived from xs:date that restricts the range of values using a maxExclusive facet.

Upvotes: 12

Related Questions