XSD 日期格式覆盖 [英] XSD date format overriding
本文介绍了XSD 日期格式覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在定义一个 XSD.我需要定义一个以 yyyymmdd 格式获取日期的元素.如何在 XSD 中定义只接受这种格式的限制?
I am defining an XSD. I need to define an element which takes date in format yyyymmdd. How can I define a restriction in XSD to only accept this format?
推荐答案
您总是可以将其定义为基于字符串的受限简单类型,受正则表达式限制:
You could always define it as a restricted simple type based on a string, restricted by a regular expression:
<xs:simpleType name="FormattedDateType">
<xs:restriction base="xs:string">
<xs:pattern value="\d{8}"/>
</xs:restriction>
</xs:simpleType>
如果你想变得更聪明,你可以调整正则表达式,使其更符合日期(例如,包含该月只能是 01 - 12 等的信息):
If you want to get really smart, you can tweak the regular expression to be even more of a match for a date (e.g. contains the info that month can only be 01 - 12 and so forth):
<xs:simpleType name="FormattedDateType">
<xs:restriction base="xs:string">
<xs:pattern value="\d{4}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])"/>
</xs:restriction>
</xs:simpleType>
马克
这篇关于XSD 日期格式覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文