[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Date Format in XSD Schema
On Wed, 2003-07-23 at 11:03, Khurram Chaudhary wrote: > Helo All > > Can anybobdy help me in specifying date format in xsd. I want to restrict > date format in dd/mm/ccyy format, and also want to make this date optional. > At the moment I am doing this > > <xs:element name="DateAdded"> > <xs:simpleType> > <xs:restriction base="xs:string"> > <xs:pattern value="[0-2][0-9][/][0-1][0-9][/][0-2][0-2][0-9][0-9]"/> > </xs:restriction> > </xs:simpleType> > </xs:element> > > I want to make this value optional. To make it optional, just enclose your regexp in "()" and add a trailing "?" I have a couple of comments on your definition, though: * Most of the time, using xs:token (the name is misleading, xs:token is *not* a token) instead of xs:string will give you the result you're expecting (accepting non significant trailing and leading whitespaces). That's also more coherent with the other WXS datatypes which all accept (with the exception of xs:string and xs:normalizeString) non significant trailing and leading whitespaces. * Do you really want to exclude days 30 and 31? My definition would thus be: <xs:element name="DateAdded"> <xs:simpleType> <xs:restriction base="xs:token"> <xs:pattern value="([0-3][0-9][/][0-1][0-9][/][0-2][0-2][0-9][0-9])?"/> </xs:restriction> </xs:simpleType> </xs:element> Of course, you could do a better control on days and months but your regexp would become more complex. Hope this helps. Eric -- Don't you think all these XML schema languages should work together? http://dsdl.org ------------------------------------------------------------------------ Eric van der Vlist http://xmlfr.org http://dyomedea.com (W3C) XML Schema ISBN:0-596-00252-1 http://oreilly.com/catalog/xmlschema ------------------------------------------------------------------------
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|