XSD 验证 xs:date 和 xs:dateTime 的错误格式 [英] XSD validates wrong format of xs:date and xs:dateTime

查看:49
本文介绍了XSD 验证 xs:date 和 xs:dateTime 的错误格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我像下面这样设置 year 部分(20512 或类似的东西)时,XSD 仍然会验证 XML.

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

任何想法.

这是一个缺陷还是我必须使用具有给定模式的simpleType?

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

谢谢

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

推荐答案

这是您的验证器中NOT 的缺陷(顺便说一句,您应该指出您正在使用哪个验证器).其他验证器(错误)的行为与您似乎期望的一样;例如,.NET 会抱怨 The value '20512-07-11' is invalid 根据其数据类型 'http://www.w3.org/2001/XMLSchema:date' - 字符串 '20512-07-11' 不是有效的 XsdDateTime 值.

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.

请参阅 XSD 规范的 本节,第 D3.3 节清楚地表明您的价值是有效的.

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

这篇关于XSD 验证 xs:date 和 xs:dateTime 的错误格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆