XSD checks for incorrect xs: date and xs: dateTime format

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

Any idea.

Is this a flaw or do I need to use simpleType with a 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"> 
+4
source share
2 answers

This vulnerability is NOT in your validator (by the way, you must indicate which validator you are using). Other mis-validators behave as you expect; e.g. .NET will 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 specification, section D3.3, which clearly states that your value is valid.

+4
source

Sorry, but why do you think 20512-07-11 is an invalid date? Astronomers may be very eager to maintain data showing that an eclipse will occur on that date.

If you want to limit your dates to a certain range, for example, to the year 2100, then you should use simpleType derived from xs: date, which limits the range of values ​​using maxExclusive facet.

+10
source

All Articles