OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Date Format in XSD Schema

[ Lists Home | Date Index | Thread Index ]

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
------------------------------------------------------------------------





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS