Using XS:date i want date in format YYYYMMDD

那年仲夏 提交于 2019-12-23 09:38:26

问题


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 ??


回答1:


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>

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.



来源:https://stackoverflow.com/questions/5039657/using-xsdate-i-want-date-in-format-yyyymmdd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!