gpt4 book ai didi

xml - 有一个空的 xs :date element being validated OK by the XSD

转载 作者:数据小太阳 更新时间:2023-10-29 01:55:38 26 4
gpt4 key购买 nike

我的 XSD 中有这个:

<xs:element name="End_Date" type="xs:date" minOccurs="0"/>

如果有日期或有空节点,我希望验证通过

<End_Date>2011-05-31T00:00:00.000</End_Date>应该没问题 <End_Date></End_Date>

我如何修改 XSD 以实现它?

我尝试了不同的东西:

nillable="true"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"

                    <xs:element name="End_Date">
<xs:simpleType>
<xs:union memberTypes="xs:date">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>

它们都不起作用。

错误:

Error detected : The 'xxxxxxxxxx:End_Date' element is invalid - The value '' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:date' - The string '' is not a valid XsdDateTime value.

最佳答案

也许您对 xs:date 和 xs:dateTime 之间的区别感到困惑。您在架构中使用了 xs:date,但您的示例是 xs:dateTime。

可以通过三种方式实现你想要的:

(a) 定义一个类型,它是 (xs:dateTime and (xs:string restriction of xs:string allowing only "")) 的联合

(b) 定义一个类型,它是 xs:dateTime 的列表,minLength = 0,maxLength = 1

(c) 将元素定义为可空。在这种情况下,实例将不得不说 xsi:nil="true",在我看来,这会使该工具变得毫无用处。

如果您尝试了其中一种方法但它不起作用,请准确告诉我们您做了什么以及它是如何失败的。

关于xml - 有一个空的 xs :date element being validated OK by the XSD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7360906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com