This section describes the built-in primitive datatype, 'time' that represents moments in a day. Leading and trailing whitespaces are allowed and trimmed. Timezone offset is optional.
"time" is a built-in datatype that uses the date/time seven-property model
to represent a moment in day with these rules:
The value space of "time" is all possible moments in day to a specific timezone or an unknow timezone.
The lexical space of "time" is all possible "time" values represented in
(hour):(minute):(second)(timezoneOffset)? patten.
"hour", "minute" and "second" are required properties.
"timezoneOffset" property is optional and no default timezone is defined.
Leading and trailing whitespaces allowed and trimmed.
To verify these rules, I wrote this simple XSD document that uses "time" datatype to declare XML elements:
Here is a sample XML document that can be used to test these declarations:
<?xml version="1.1"?>
<!-- time_datatype_test.xml
- Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<Time_Datatype_Test>
<!-- 3 valid "Time" elements -->
<Time> 21:32:52Z </Time>
<Time> 21:32:52.12346789 </Time>
<Time>21:32:52-05:00</Time>
<!-- 2 invalid "Time" elements -->
<Time> 23:59 </Time>
<Time> 1971-05-16T21:32:52 </Time>
</Time_Datatype_Test>
When validating this XML document with my XsdSchemaValidator.java program presented earlier in the book,
I get 4 groups of errors for 4 invalid XML elements:
c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator
time_datatype_test.xsd time_datatype_test.xml
Error:
Line number: 13
Column number: 31
Message: cvc-datatype-valid.1.2.1: '23:59' is not a valid value for
'time'. (Missing a property in "time")
Error:
Line number: 13
Column number: 31
Message: cvc-type.3.1.3: The value ' 23:59 ' of element
'Time' is not valid.
Error:
Line number: 14
Column number: 40
Message: cvc-datatype-valid.1.2.1: '1971-05-16T21:32:52' is not a
valid value for 'time'. ("date" is not allowed in "time")
Error:
Line number: 14
Column number: 40
Message: cvc-type.3.1.3: The value ' 1971-05-16T21:32:52 ' of
element 'Time' is not valid.
Failed with errors: 4