使用 XS:date 我想要格式为 YYYYMMDD 的日期 [英] Using XS:date i want date in format YYYYMMDD

查看:20
本文介绍了使用 XS:date 我想要格式为 YYYYMMDD 的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 XSD 我只想在我的 xml 字段中接受格式为 YYYYMMDD 的日期..那我该怎么做

Using XSD i want to only accept date of the format YYYYMMDD in my xml field .. So how can i do that

我在一个例子中看到了这个,这会起作用吗??

I saw this in an example will this work ??

推荐答案

XML schema dateTime 定义为 ISO8601,但有一些例外,你应该坚持这一点,否则你会遇到严重的互操作性问题.如果您想使用不同的格式发送/接收日期,请使用带有正则表达式限制的 simpleType 并在应用程序代码中解析/格式化日期:

XML schema defines dateTime as ISO8601 with some exceptions and you should stick with this, otherwise you will get serious interoperability issues. If you want to send/receive date using different format, use simpleType with regular expression restriction and parse/format the date in your application code:

<xs:simpleType name="CustomDate">
    <xs:restriction base="xs:string">
        <xs:pattern value="\d{8}"/>
    </xs:restriction>
</xs:simpleType>

如果您真的想要处理内置类型(非常不明智),您的 XML 框架/库可能会对此提供一些支持.例如在 Java/JAXB 中,您可以将自定义转换器/格式化程序应用于任何类型,以便在客户端/服务器代码中您仍然使用 Date 对象(而不是 8 位 String>),但使用您的自定义例程对其进行编组/解组.

If you really want to mess around with built-in types (highly inadvisable), your XML framework/library might have some support for that. For instance in Java/JAXB you can apply custom transformers/formatters to any type, so that in client/server code you are still using Date object (not the 8-digit String), but it is marshalled/unmarshalled using your custom routine.

这篇关于使用 XS:date 我想要格式为 YYYYMMDD 的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆