【发布时间】:2011-09-14 03:31:44
【问题描述】:
我从外部公司接收这两种形式的 xml 数据
<currencydate>20110910</currencydate>
<currencydate/>
我想使用一个模式来验证这个日期确实有这样的格式 YYYYMMDD
<xs:element name="currencydate" type="dateType"/>
<xs:simpleType name="dateType">
<xs:restriction base="xs:string">
<xs:pattern value="[0-2][0-9]{3}[0-1][0-9][0-3][0-9]"/>
</xs:restriction>
</xs:simpleType>
这很好用。但是验证在空元素上中断
所以我像这样添加了 minOccurs
<xs:element name="currencydate" type="dateType" minOccurs="0"/>
没有成功,所以我添加了 nillable
<xs:element name="currencydate" nillable="true" type="dateType" minOccurs="0"/>
没有成功,我猜元素在那里,所以它会检查模式。所以我改变了模式
<xs:pattern value="[0-2][0-9]{3}[0-1][0-9][0-3][0-9]|"/>
我只添加了指示该值可以为空的管道。但还是没有成功。
所以我的问题是:我怎样才能检查数据模式但也允许值
<currencydate/>
请注意,我从不提供 xsd 也不愿意为我更改任何内容的外部公司收到此数据。
【问题讨论】:
标签: xsd