Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xsd:dateTime with specific precision

Tags:

xml

precision

xsd

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.

like image 823
kojiro Avatar asked Jan 01 '26 02:01

kojiro


1 Answers

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.

like image 117
sergioFC Avatar answered Jan 05 '26 14:01

sergioFC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!