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

Re: Time without Seconds

From: Rowan Sylvester-Bradley <rowan@sylvester-bradley.org>
Date: Mon, 13 Oct 2008 12:48:58 +0100
Message-ID: <731EEED3A9A545E18D9669BF5A3B2B29@SSK.local>
To: <xmlschema-dev@w3.org>
Re: Time without Seconds

Pete,

Many thanks, that works fine. I ended up with the following, which accepts 
times with or without seconds:

<xsd:simpleType name="time_hh_mm">
  <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-1][0-9]:[0-5][0-9]"/>
    <xsd:pattern value="[0-1][0-9]:[0-5][0-9]:[0-5][0-9]"/>
    <xsd:pattern value="2[0-3]:[0-5][0-9]"/>
    <xsd:pattern value="2[0-3]:[0-5][0-9]:[0-5][0-9]"/>
  </xsd:restriction>
</xsd:simpleType>

Rowan

----- Original Message ----- 
From: "Pete Cordell" <petexmldev@codalogic.com>
To: "Rowan Sylvester-Bradley" <rowan@sylvester-bradley.org>; 
<xmlschema-dev@w3.org>
Sent: Monday, October 13, 2008 9:30 AM
Subject: Re: Time wihtout Seconds


>
> ----- Original Message From: "Rowan Sylvester-Bradley"
>
>> How do I write a schema that will validate an element containing a
>> time in the format hh:mm (without any seconds)? I'm trying to write
>> a schema for an existing XML file that's generated by a piece of
>> software which I have no access to, so I can't just add the seconds...
>
> In that case you probably want to have a base type of an xs:string and 
> then restrict it using an xs:pattern facet.  Something like:
>
> <xs:simpleType name="myTime">
> <xs:restriction base="xs:string">
>  <xs:pattern value="[0-2][0-9]:[0-5][0-9]"/>
> </xs:restriction>
> </xs:simpleType>
>
> Or possibly even better:
>
> <xs:simpleType name="myTime">
> <xs:restriction base="xs:string">
>  <xs:pattern value="[0-1][0-9]:[0-5][0-9]"/>
>  <xs:pattern value="2[0-3]:[0-5][0-9]"/>
> </xs:restriction>
> </xs:simpleType>
>
> (I'm pretty sure the pattern facets have an OR type relationship rather 
> than an AND type relationship.  I'm sure someone will correct me if I'm 
> wrong.)
>
> HTH,
>
> Pete Cordell
> Codalogic Ltd
> Interface XML to C++ the easy way using XML C++
> data binding to convert XSD schemas to C++ classes.
> Visit http://www.codalogic.com/lmx/ for more info
Received on Monday, 13 October 2008 11:51:36 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
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-2007 All Rights Reserved.