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

旧巷老猫 提交于 2020-01-24 08:20:46

问题


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">

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11691158/xsd-validates-wrong-format-of-xsdate-and-xsdatetime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!