[英]Apply restriction to time attribute in XML Schema
I want to apply a specific restriction to an XML Schema (on which I have very little experience). 我想对XML Schema应用一个特定的限制(我很少有经验)。
I have an attribute of xsd:time
type: 我有一个
xsd:time
类型的属性:
<xsd:attribute name="hour" type="xsd:time" use="required"/>
What I want to to is apply a restriction so that the XML will be valid only on half-hour time intervals. 我想要的是应用限制,以便XML仅在半小时的时间间隔内有效。 For example, 10:00, 12:30, 15:30, 20:00 would be valid values for the hour attribute but 10:45, 11:12, 15:34 etc would not.
例如, 10:00,12:30,15:30,20:00将是小时属性的有效值,但不是10:45,11:12,15:34等。
How can I achieve this? 我怎样才能做到这一点? My search did not give out something useful.
我的搜索没有给出有用的东西。
Thank you in advance. 先感谢您。
You could define your time in this way. 你可以用这种方式定义你的时间。
<xsd:attribute name="hour" type="Time" use="required"/>
<xsd:simpleType name="Time">
<xsd:restriction base="xsd:time">
<xsd:enumeration value="00:00:00"/>
<xsd:enumeration value="00:30:00"/>
<xsd:enumeration value="01:00:00"/>
<xsd:enumeration value="01:30:00"/>
<xsd:enumeration value="02:00:00"/>
<xsd:enumeration value="02:30:00"/>
<xsd:enumeration value="03:00:00"/>
<xsd:enumeration value="03:30:00"/>
<!-- etc etc -->
</xsd:restriction>
</xsd:simpleType>
or 要么
<xsd:simpleType name="Time">
<xsd:restriction base="xsd:time">
<xsd:pattern value="((0[0-9]|1[0-9]|2[0-3]):[0|3][0]:[0][0])"/>
</xsd:restriction>
</xsd:simpleType>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.