In the xml schema data type --> date allows date as yyyy-mm-dd format by default.
How can we modify it so that it accepts yyyy/mm/dd format style instead ?
In the xml schema data type --> date allows date as yyyy-mm-dd format by default.
How can we modify it so that it accepts yyyy/mm/dd format style instead ?
You can't get the standard xs:date type to accept formats other than the standard format. What you can do is to define a string data type with a pattern constraint; but it won't have date semantics, for example it will accept 1999/02/29.
Saxon's XSD processor has an experimental extension, saxon:preprocess, which allows you to change the lexical representation of a data type. Not many people use it, of course, because they want their schemas to be interoperable; but it does exactly what you want so I thought I would mention it.
Another solution which is often overlooked, and which is perhaps more practical, is for your processing pipeline to do a transformation step before it does the validation step. This approach can be used to overcome many of the limitations of XML Schema, and it isn't widely enough known.
You cant change the date type to a specific format but you can take it as a string and choose a specific format that you want.
For the format of date MM/DD/YYYY. the code snippet is given below.
<xs:element name="StartDate">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="\d{2}[/]\d{2}[/]\d{4}"></xs:pattern>
<xs:length value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
you can check this regex posted by melwil. it worked for me !
((0[1-9]|[1-2]\d|3[01])-(0[13578]|1[02])|([0-2]\d|30)-(0[469]|11)|(0[1-9]|1\d|2[0-8])-02)-\d{4}|(0[1-9]|[12]\d)-02-(([02468][048]|[13579][26])00|(\d{2}([02468][48]|[2468][048]|[13579][26])))