Validate enumeration based on date ranges in XSD 1.0?

133 Views Asked by At

In XSD I would like to define a type Country including a restriction which sets the list of country names that can be used. Which can be done easily by using enumeration as a restriction.

However, this list will vary when time goes by. For example: in the past we had Yugoslavia which doesn't exist anymore; Croatia, Slovenia, etc appeared instead. So a country will have a start date and (potentially) an end date. StartDate and EndDate will set the date range of existence for each particular country.

When validating an XML I would like to verify whether the XML refers to an existing country. Therefore the XML will also contain variable ReferenceDate which will be used to check against StartDate and EndDate.

Actually I would like to define type Country with attributes CountryName, StartDate and Enddate set. When validating the XML with - for example - values Croatia and ReferenceDate I would like to verify whether Croatia is a valid country at date ReferenceDate, using type Country being defined in the XSD.

Any ideas with the restriction given that I'm using XSD 1.0?

2

There are 2 best solutions below

1
On

You could consider a framework that allows you to generate the schema appropriate to a particular date (typically by applying an XSLT transformation to some kind of meta-schema).

For example, your meta-schema could be essentially an XSD file where any element can have start-date and end-date attributes, and you could process this very easily using XSLT to retain only the elements that apply on a particular date.

4
On

XSD 1.0

Your constraints cannot be enforced.

XSD 1.1

You can write an assertion to ensure current-date() is within a range of values in the XML instance document. You cannot make assertions over ranges given by types within the XSD.

Your constraints as stated would probably be best enforced via custom application code.