Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

iso date format

Status
Not open for further replies.

ksestak

Programmer
Joined
Jul 1, 2008
Messages
1
Location
SK

Hello all,

I want to define a element in type date like this:

for example: <xs:element name="navdate" form="unqualified" type="xs:date"/>

But my date is in format DD/MM/YYYY and for the validation the format have to be YYYY-MM-DD.

It is possible to change the validation format ? Thanks.
 
[1] To do so, you start with the base xs:string type and impose a restriction on it. The restriction is best through a regular expression. Then you find a handy regexp for the dd/mm/yyyy pattern with more or less sophistication, depending on how coarse or how fine you are happy enough.

[2] This is one of the realization of the above appraoch.
[tt]
<!-- arbitrarily called uk_date for date of dd/mm/ccyy format -->
<xs:simpleType name="uk_date">
<xs:restriction base="xs:string">
<!--
ref [ignore][/ignore]
an entry accredited to Dany Lauener
-->
<xs:pattern value="(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))" />
</xs:restriction>
</xs:simpleType>
[/tt]
[2.1] Note that you don't put anchors ^ and $ to the pattern in the schema, you don't need to.

[3] Then you set up the element "navdate" like this.
[tt]
<xs:element name="navdate" form="unqualified" type="uk_date"/>
[/tt]
and things should be set.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top