开发者

Modify xsd:dateTime simple type to use different date-and-time separator

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:dateTimewould 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 simpleTypedefinition 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:stringand de开发者_运维技巧fine 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.


You can do a regular expression pattern restriction on the xs:string data type.

For example:

<xs:element name="specialDateTime">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9][0-9]/[0-9][0-9]/[0-9][0-9] [0-9][0-9]:[0-9][9-9]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

Edit

I found this example at http://www.cs.wisc.edu/condor/classad/refman/node9.html. It looks like you can put a pattern restriction on a dateTime:

<xsd:simpleType>
  <xsd:restriction base="xsd:dateTime">
    <xsd:pattern value="\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d[+\-]\d\d:\d\d" />
  </xsd:restriction>
</xsd:simpleType>

Hope that helps.


I don't think you can derive something else from xsd:dateTime, as the XML processors will not be able to understand this. Your best bet is to use a string with the right pattern.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜