[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Date Format in XSD Schema


xsd date format
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!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.