Reputation: 1654
I have an XSD with the following element
<element name="fromDate" type="date" maxOccurs="1" minOccurs="1" />
And I have an XML with the following element
<fromDate>20100-11-22</fromDate>
If I validate that XML against the above XSD, it gives no errors and takes 20100-11-22 as a valid date. Why is this happening? How to force it to check for YYYY instead of taking YYYYY also as valid?
Update
Upon further reading, found out that according to W3C specs lexical representation on date time allows "four-or-more digit optionally negative-signed numeral that represents the year" [1].
[1] https://www.w3.org/TR/xmlschema-2/#dateTime-lexical-representation
Upvotes: 1
Views: 785
Reputation: 111726
You can use a xs:pattern
to restrict the number of year digits to four, if you don't care about a Y2K-like problem in the year 10,000:
<xs:simpleType name="ShortSightedDate">
<xs:restriction base="xs:date">
<xs:pattern value="\d{4}-\d{2}-\d{2}"/>
</xs:restriction>
</xs:simpleType>
Upvotes: 1