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?
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.