An XSD I work with has an element like:
<xsd:element name="TdlOrderTimestamp" type="xsd:dateTime" minOccurs="0"/>
but I'm being told that the system actually requires three decimal points of precision on the seconds. This is allowed by xsd:dateTime, but not required by it.
We are requiring:
<TdlOrderTimestamp>2015-05-12T18:58:02+00:00</TdlOrderTimestamp>
We should be requiring:
<TdlOrderTimestamp>2015-05-12T18:58:02.123+00:00</TdlOrderTimestamp>
What's the simplest way to specify this requirement in XSD? Ideally, I'd like to stick as close to xsd:dateTime and ISO8601's other idioms and idiosyncrasies as possible.
A simple solution is defining a new simple type that extends xsd:dateTime and adds a pattern restriction indicating that the value must contain a dot followed by three digits. Example:
<xsd:simpleType name="dateTimeWithPrecision">
<xsd:restriction base="xsd:dateTime">
<xsd:pattern value=".*\.\d{3}.*"/>
</xsd:restriction>
</xsd:simpleType>
You can adapt the pattern to other desired dateTime formats if you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With