Friday, April 20, 2012

XSD: how can I accept data that matches any of a set of types?

In my schema, I would like to accept an element containing data that is formatted as either date or dateTime.



For example, any of these elements should validate:



<event_ts>2012-04-18</event_ts>
<event_ts>2012-04-18T12:00:00</event_ts>
<event_ts>2012-04-18T12:00:00Z</event_ts>
<event_ts>2012-04-18T12:00:00-05:00</event_ts>


If I just use the dateTime type for this element, my first example will not pass validation, as the dateTime spec dictates that the time of day portion must be present.



Does something like an enumeration of types, rather than explicit strings, exist in XML Schema?



I would really rather avoid reinventing the ISO 8601 wheel with a big regex here.





No comments:

Post a Comment