问题
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