I have a legacy system that produces XML with timestamps similar to ISO 8601, but with space used to separate date and time. E.g. 2009-12-31 00:00:00. I would like to define a schema that defines the possible range for these timestamps. xsd:dateTime
would be well suited for that purpose, however, it uses T as the separator between date and time. I cannot modify the legacy system to return timestamps using T as a separator.
Is there a way to have a simpleType
definition that derives from xsd:dateTime
, but alters the separator or do I have to rely on a string with an appropriate pattern and human readable comments?
Update: As I understand, I can use a pattern for dateTime to restrict the range of dateTime objects for input, but this does not alter the separator character.
Example:
<xs:restriction base="xs:dateTime">
<xs:pattern value="[2].*:[0-9]{2}"/>
</xs:restriction>
This would only allow for dateTime with years starting with 2000 and without fractional seconds and time zone information.
Summary of answers:
It is not possible to use xs:dateTime
as the base type for this. It is however possible to use xs:string
and define a pattern.
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{4}-[01][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-6][0-9]"/>
</xs:restriction>
By using a string, of course, any automatic tools that use the Schema to create language bindings will also retrieve a string, conversion to the appropriate language type for date/time has to be done by hand.