Xml 架构和日期时间
我正在开始一个新项目,其中涉及跨多个平台(Windows、Windows Mobile、Iphone、Ipad 以及更多尚未发现的平台!)的大量 xml 和架构使用。该 xml 平台必须能够交换来自世界各地的日期时间,因为我们的产品目前正在澳大利亚、加拿大和美国实施。
日期时间通常是在不同平台和语言之间引起最多问题的一种“类型”。
我应该相信内置的日期类型吗?或者我应该将每个日期分解为几个小节,例如小时、分钟、秒、日、月、年、时区等的元素或属性。
我想了解上述每个选项的优缺点。
编辑:添加了 2 个后续问题以更加清晰
如果使用纯 xml 日期“类型”,如何确保所有客户端都以这种格式正确写入日期?
我知道 .net 我可以使用 DateTime.ToUniversalTime() 其他语言是否有等效的,或者是 XML 写入 dll 控制转换为国际时间?
谢谢 皮特
I'm beginning a new project which involves heavy xml and schema use accross multiple platforms (windows, windows mobile, Iphone, Ipad, and more which are yet to be discovered!). This xml platform has to be able to exchange date times from all over the world as our product is currently being implemented in Australia as well as in Canada and USA.
Date times are generally the one "type" that causes the most issues between different platforms and languages.
Should I trust the built in date type? or should I break down each date into it's subsections, e.g. elements or attributes for hours, mins, seconds, day, month, year, timezone etc.
I'd like to understand the pro's and con's of each options above.
EDIT: Added 2 follow up questions to get more clarity
if using the plain xml date "type" how do I ensure that all clients are correctly writing the date in this format?
I know that .net I can use DateTime.ToUniversalTime() do other languages have the equivalent, or is it the XML writing dll's that control the conversion to international time?
Thanks
Pete
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XML 模式中的“内置”日期类型是国际标准。我无法想象你如何能比你自己做得更好。
来自 Eric van der 的 XML 架构:W3C 面向对象的 XML 描述 Vlist,第 16 章,“数据类型参考指南”,“xs:dateTime”:
说明
此数据类型描述由日期和时间的组合标识的时刻 (sic)。它的值空间在 ISO 8601 第 5.4 章中被描述为“日期和时间的组合”。它的词法空间是扩展格式“[-]CCYY-MM-DDThh:mm:ss[Z|(+|- )hh:mm]”。时区可以指定为“Z”(UTC) 或“(+|-)hh:mm”。未指定的时区被视为“未确定”。
示例
xs:dateTime
的有效值包括:“2001-10-26T21:32:52”、“2001-10-26T21:32:52+02:00”、“2001-10-26T19” :32:52Z”、“2001-10-26T19:32:52+00:00”、“-2001-10-26T21:32:52”或“2001-10-26T21:32:52.12679”。以下值无效:“2001-10-26”(必须指定所有部分)、“2001-10-26T21:32”(必须指定所有部分)、“2001-10-26T25:32:” 52+02:00”(小时部分 (25) 超出范围)或“01-10-26T21:32”(必须指定所有部分)。
请注意,您可以要求通过使用
pattern
限制来限制值来指定时区。The "built in" date types in XML schema are an International standard. I can't imagine how you could do better than that on your own.
From XML Schema: The W3C's Object-Oriented Descriptions for XML by Eric van der Vlist, Chapter 16, "Datatype Reference Guide", "xs:dateTime":
Description
This datatype describes instants(sic) identified by the combination of a date and a time. Its value space is described as a "combination of date and time of day" in Chapter 5.4 of ISO 8601. Its lexical space is the extended format "[-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm]". The timezone may be specified as "Z" (UTC) or "(+|-)hh:mm." Timezones that are not specified are considered "undetermined."
Example
Valid values for
xs:dateTime
include: "2001-10-26T21:32:52", "2001-10-26T21:32:52+02:00", "2001-10-26T19:32:52Z", "2001-10-26T19:32:52+00:00", "-2001-10-26T21:32:52", or "2001-10-26T21:32:52.12679".The following values would be invalid: "2001-10-26" (all the parts must be specified), "2001-10-26T21:32" (all the parts must be specified), "2001-10-26T25:32:52+02:00" (the hours part (25) is out of range), or "01-10-26T21:32" (all the parts must be specified).
Note that you can require that a timezone be specified by restricting the value with a
pattern
restriction.