Re: Changing Data Format

Hi Prasanna,

> As the W3c Standard for thge xs:date is "YYYY-MM-DD" , I actually
> want to change the format to "MM-DD-YYYY" in the XSD file which will
> except the dates with only my userdfined format. Is this possible in
> any of the patterns defined int eh W3c Specifications for XML Schema

You could use a regular expression to create a simple data type that
restricted strings (or tokens) to look like that. It would be
something like:

<xs:simpleType name="AmericanDate">
  <xs:restriction base="xs:token">
    <xs:pattern value="[0-9]{2}-[0-9]{2}-[0-9]{4}" />
  </xs:restriction>
</xs:simpleType>

or maybe you'd want the pattern to be:

  ((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3[0-1]))-[0-9]{4}

though that still wouldn't take into account the fact that February
can only have a maximum of 29 days, and as for leap years - I doubt
you could put that in a regular expression...

Which is why using xs:date is better - it gives you a lot more power,
because the validator can not only test that the numbers all make
sense, it can also test that it's actually a valid date.

Plus, when an application receives an element or attribute with an
xs:date it knows that it's a date and can manipulate it as a date -
get the day, month and year, add a month to it and that kind of thing.
When it receives a string in the format MM-DD-YYYY it doesn't
automatically know it's a date - you have to do a lot more coding to
get it to process the string as one.

So unless you know that your XML will never be used by applications
that care about the validity of dates or manipulating the value as a
date, you should use xs:date instead. You can then use something else
(like XPath/XSLT or your favourite programming language) to manipulate
the date to the format you want for display.

Cheers,

Jeni

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

Received on Wednesday, 21 November 2001 04:25:17 UTC