FredFloete
FredFloete

Reputation: 659

XML Schema restrictions on the current date

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.

Upvotes: 0

Views: 5197

Answers (1)

C. M. Sperberg-McQueen
C. M. Sperberg-McQueen

Reputation: 25054

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"/>
    

Upvotes: 1

Related Questions