[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] ANN: Portable Data Component -- time interval (start/end orstart/durati
Hi Folks, This is an extension of the start/end portable data component. A time interval may be expressed using either of these: - start and end values, or - start and duration values. Here are examples using start/duration. Example #1 The class starts on May 3, 2011 at 8am and runs for 8 hours: <class> <start>2011-05-03T08:00:00</start> <duration>PT8H</duration> </class> Example #2 My vacation begins June 22, 2011 and is for 3 days: <vacation> <start>2011-06-22</start> <duration>P3D</duration> </vacation> The constraints on the start/end values are those described earlier. There is one constraint on the start/duration values: the duration must not be a negative value. Determining that duration is not a negative value is not straightforward. One would think that this XPath expression would do the job: xs:duration(duration) gt xs:duration("P0Y") However, that is not correct. It will generate this error: xs:duration is not an ordered type Instead, what is required is to treat duration as a string and check that the string starts with the letter 'P' (i.e., not the letter '-'): starts-with(duration, 'P') Here is the time-interval portable data component: <xs:complexType name="time-interval"> <xs:sequence> <xs:element name="start"> <xs:simpleType> <xs:union memberTypes="xs:date xs:time xs:dateTime" /> </xs:simpleType> </xs:element> <xs:choice> <xs:element name="end" minOccurs="0"> <xs:simpleType> <xs:union memberTypes="xs:date xs:time xs:dateTime" /> </xs:simpleType> </xs:element> <xs:element name="duration" type="xs:duration" /> </xs:choice> </xs:sequence> <xs:assert test="if (exists(end)) then if (start castable as xs:dateTime) then xs:dateTime(end) gt xs:dateTime(start) else if (start castable as xs:date) then xs:date(end) gt xs:date(start) else if (start castable as xs:time) then xs:time(end) gt xs:time(start) else true() else if (exists(duration)) then starts-with(duration, 'P') else true()" /> </xs:complexType> A summary of all our discussions on Portable Data Components may be found here: http://www.xfront.com/xml-schema-1-1/best-practice/portable-data-components/Portable-Data-Components.pdf /Roger [Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] |
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
|