Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using XS:date i want date in format YYYYMMDD

Tags:

xml

w3c

xsd

Using XSD i want to only accept date of the format YYYYMMDD in my xml field .. So how can i do that

I saw this in an example will this work ??

like image 493
Praneel PIDIKITI Avatar asked Feb 18 '11 09:02

Praneel PIDIKITI


1 Answers

XML schema defines dateTime as ISO8601 with some exceptions and you should stick with this, otherwise you will get serious interoperability issues. If you want to send/receive date using different format, use simpleType with regular expression restriction and parse/format the date in your application code:

<xs:simpleType name="CustomDate">
    <xs:restriction base="xs:string">
        <xs:pattern value="\d{8}"/>
    </xs:restriction>
</xs:simpleType>

If you really want to mess around with built-in types (highly inadvisable), your XML framework/library might have some support for that. For instance in Java/JAXB you can apply custom transformers/formatters to any type, so that in client/server code you are still using Date object (not the 8-digit String), but it is marshalled/unmarshalled using your custom routine.

like image 86
Tomasz Nurkiewicz Avatar answered Sep 21 '22 15:09

Tomasz Nurkiewicz