Apply time attribute constraint in XML schema

I want to apply a specific constraint to an XML schema (in which I have very little experience).

I have an xsd:time type attribute:

 <xsd:attribute name="hour" type="xsd:time" use="required"/> 

I want to use a constraint so that XML is valid only after half an hour. For example, 10:00, 12:30, 15:30, 20:00 will be valid values ​​for the hour attribute, but 10:45, 11:12, 15:34, etc. Will not.

How can i achieve this? My search yielded nothing useful.

Thanks in advance.

+5
source share
1 answer

You could define your time 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> 
+3
source

All Articles