XSD Tutorials - Herong's Tutorial Examples - v5.23, by Herong Yang
"time" Datatype Values and Representations
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:
To verify these rules, I wrote this simple XSD document that uses "time" datatype to declare XML elements:
<?xml version="1.1"?> <!-- time_datatype_test.xsd - Copyright (c) 2002-2013 HerongYang.com. All Rights Reserved. --> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Time_Datatype_Test"> <xs:complexType> <xs:sequence> <xs:element name="Time" type="xs:time" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Here is a sample XML document that can be used to test these declarations:
<?xml version="1.1"?> <!-- time_datatype_test.xml - Copyright (c) 2002-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:
herong> 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
Table of Contents
XML Editor and Schema Processor - XMLPad
Java API for XML Processing - JAXP
JAXP - XML Schema (XSD) Validation
Xerces2 Java Parser - Java API of XML Parsers
Introduction of XSD Built-in Datatypes
"string" and Its Derived Datatypes
"decimal" and Its Derived Datatypes
►"dateTime" and Its Related Datatypes
Date/Time Seven-Property Model
"dateTime" Datatype Values and Representations
"dateTimeStamp" Datatype Values and Representations
"date" Datatype Values and Representations
►"time" Datatype Values and Representations
"gYear", "gMonth" and "gDay" Datatypes
"gYearMonth" and "gMonthDay" Datatypes
"duration" Datatype Values and Representations
"yearMonthDuration" Datatype Values and Representations
"dayTimeDuration" Datatype Values and Representations
Date, Time and Duration Datatype Summary
Miscellaneous Built-in Datatypes
Facets, Constraining Facets and Restriction Datatypes
"simpleType" - Defining Your Own Simple Datatypes
Identity-Constraints: unique, key and keyref
Assertion as Custom Validation Rules
XML Schema Location and Namespace in XML Documents
Overriding Element Types in XML Documents