Re: date

Hi Georg,

> I am trying xerces 2.0.0.(after 1,3,1). With 1.3.1 I used atribute
> with type date in format dd.mm.yyyy with optional one or two digits
> "dd" and "mm". But now I read, that in new version is type date in
> format yyyy-mm-dd and required two digits on position "dd" and "mm".
> I need accept xml files with the same format everything! How can I
> set the format of date?

The only dates that W3C XML Schema recognises are those that follow
the ISO 8601 format of YYYY-MM-DD. It doesn't think that "30-Aug-02" is
a date, nor "30.8.2002", just as it doesn't think that "minus one" is
an integer or "3 weeks" a duration.

To allow an element or attribute to take both an xs:date (YYYY-MM-DD
format) and a token in the format d.m.yyyy, you need to create a
simple type that unions together the two formats. The latter format
needs to be created by restricting xs:token using a regular
expression. Something like:

<xs:simpleType name="myDate">
  <xs:union memberTypes="xs:date">
    <xs:simpleType>
      <xs:restriction base="xs:token">
        <xs:pattern value="[0-3]?[0-9].[0-1]?[0-9].[0-9]{4}" />
      </xs:restriction>
    </xs:simpleType>
  </xs:union>
</xs:simpleType>

Note that the above pattern doesn't do any checking to see whether
the token-in-the-format-d.m.yyyy actually represents a valid date --
the value 29.2.2002 will count as valid even though this year wasn't a
leap year, for example.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Friday, 30 August 2002 06:03:31 UTC