Dana
Dana

Reputation: 2739

Custom date format in XML-Schema

I am creating an xml schema, and I want to support a custom date format:
Thu Dec 11 14:17:20 2008

Currently I'm using the following pattern type:

<xs:simpleType name="Date_Type">
    <xs:restriction base="xs:token">
        <xs:pattern value="(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|June|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [0-9]{4}"/>
    </xs:restriction>
</xs:simpleType>

Is there a simpler (more elegant) way of doing this using XML-schema?

Upvotes: 2

Views: 9839

Answers (1)

David Norman
David Norman

Reputation: 19879

XML with schema is intended to store data; as other have pointed out there is alreay a standard way to store dates. It look like you want to store formatted data, which is mixing the model and the view, as it were.

It's possible that you'll be be fine doing this, but eventually you might want to do something like an XSLT filter that picks out items whose dates are between two given dates. Then you'll be in trouble.

Upvotes: 3

Related Questions