我在架构中添加 type="date" 时遇到问题,因为只要它为 null 就会引发编组错误。我发现对于元素,我们可以添加一个类似 nullable="true" 的属性并摆脱这个问题。但是,无法找到类似的属性方式。有没有办法避免这个属性问题?
谢谢!
不知道这是否是您需要的,但我遇到了空日期问题(在 xml:date="")中,我像这样处理它:
<xs:simpleType name="mydatetype">
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:date">
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0" />
<xs:maxLength value="0" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
不幸的是,属性没有“nillable”选项。
但是,您可以使用说明符修饰属性,该use="optional"
说明符应该处理属性不存在的情况(不应导致错误)。
马克