- Language Settings
- Space Handling
- Date and Time Representation
- Summary
- References
Date and Time Representation
As is true for any software application, XML documents should store date and time information in a locale-independent manner or with enough information about what locale was used to format it.
Time stamps will become more and more important as distributed applications across several time zones will increase the complexity of synchronizing tasks.
One challenge with XML is that documents can be used for a wide range of applications and can serve many different purposes. Ideally, storing date/time information as a number would be the best way to proceed: The correct formatting could be applied at rendering time. However, this is practical only if you process the documents with your own application, such as SOAP.
In many cases, you will have XML documents in which the user will interact directly with the file, without the benefit of a reformatting of the content. In such occurrences, the date/time must be directly readable by the user.
ISO Format
As always, the best way to implement locale-specific information is to use existing standards when possible. ISO offers a wide palette of standardized representations for date, time, duration, and intervals in the ISO 8601:1988 specifications.
Each application can have different requirements and you should pick the format that best fits the type of information you need to represent.
As an example, you can look at the TMX format. This XML standard for translation memory exchange uses several attributes related to date/time information: changedate, creationdate, and lastusagedate. All three of them use the same format:
YYYYMMDDThhmmssZ
For instance, the string 20000811T133402Z represents August 11, 2000 at 1:34 p.m. 2 seconds, in UTC.
Listing 3.8 presents a short TMX document (just one entry: a software string in English and Esperanto) generated by a translation memory utility that demonstrates how the different attributes are used.
Listing 3.8 Date_Time.tmxTMX Document with the Three Date/Time Attributes
<?xml version="1.0" ?> <!DOCTYPE tmx SYSTEM "tmx12.dtd"> <tmx xmlns="http://www.lisa.org/tmx" version="1.2"> <header creationtool="Rainbow" creationtoolversion="2.00-1" datatype="PlainText" segtype="sentence" adminlang="en-US" srclang="en-US" o-tmf="Rainbow" creationdate="20000101T163812Z" creationid="YvesS" changedate="20000314T023401Z" changeid="Amity" o-encoding="iso-8859-3"> </header> <body> <tu tuid="0001" datatype="Text" usagecount="2" lastusagedate="20000314T023401Z"> <tuv lang="EN" creationdate="20000212T153400Z"> <seg>Search for PATTERN in each FILE or standard input.</seg> </tuv> <tuv lang="EO" creationdate="20000309T021145Z" changedate="20000314T023401Z"> <seg>Ser_i pri _ABLONO en _iu DOSIERO a_ la normala enigo.</seg> </tuv> </tu> </body> </tmx>
When developing a new schema or porting an XML DTD to a schema definition, you might want to take advantage of the predefined types for date and time. The XML Schema offers a collection of predefined types for date, time, duration, and intervals.
For example, the three date/time-related attributes we have seen in TMX would be of the type timeInstant, as in the excerpt below:
<attribute name='lastusagedate' type='timeInstant' use='optional'/> <attribute name='creationdate' type='timeInstant' use='optional'/> <attribute name='changedate' type='timeInstant' use='optional'/>