Question

Is it possible to have restricts of the XSD date and time data types for the current date? For example, if you want to set the maxInclusive of a date to the current date:

<xs:element name="DateOfBirths" type="birthsDate"/>    
 <xs:simpleType name="birthsDate">
  <xs:restriction base="xs:date">
   <xs:minInclusive value="1920-01-01"/>
   <xs:maxInclusive value="current-date()" fixed="true"/>
  </xs:restriction>
 </xs:simpleType>

If this is not possible per default, does a workaround exist? Any help would be appreciated.

Was it helpful?

Solution

XSD doesn't support calls to XPath functions in setting facet values, so (as you presumably already know) the code in the question won't work.

The most obvious workarounds are

  • Use XSD 1.1 and check the constraint in an assertion.
  • Use Schematron and check the constraint in an assertion.
  • Check the constraint at the application level.
  • Move the declaration of the birthDate type into a schema document of its own; periodically generate a new version of that schema document, either by hand or using a cron job or something similar. The schema document generated today would have

    <xs:maxInclusive value="2013-06-20"/>
    

    and the schema document generated tomorrow would have

    <xs:maxInclusive value="2013-06-21"/>
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top