I have an XSD file where I have defined a simple type restricted by an enumeration like this.
<xs:simpleType name="myEnumStrings">
<xs:restriction base="xs:string">
<xs:enumeration value="first"/>
<xs:enumeration value="second"/>
...
<xs:enumeration value="last"/>
</xs:restriction>
</xs:simpleType>
I have a second simple type, the value of which depends on the possible values of the myEnumStrings in a complex way that I can describe only with a pattern.
<xs:simpleType name="patternRestrictedType">
<xs:restriction base="xs:string">
<xs:pattern value="..."/>
</xs:restriction>
</xs:simpleType>
Currently I’m duplicating the information in the regular expression by using the string
(first|second|...|last)
whenever I want to refer to the myEnumStrings. This though is a trouble maker and a source of bugs because I need to keep all the regular expressions up to date when I modify the myEnumStrings type.
Is there a way to reference in the regular expression the possible values of the myEnumStrings to avoid this duplication? If this is not possible, is there a way to define globaly the string (first|second|…|last) to be reused in the regular expressions, to limit the duplication at only two places and to make the regular expressions more readable?
XSD is not good at it, as in “elegant”. The only things that might help is the use of unions; it would work based on your specific pattern, but it may not work based on something else you did not describe.
The idea is to reuse enumerations. To do that, you create simple types that encapsulate the enums you wish to reuse. Just an observation, having more than one enumerated values is technically equivalent with a disjunction of its values (in terms of patterns).
The above achieves the reuse of enumerations, or anything else you define as constraints for union members.
Valid XML for root-a:
Valid XML for root-b:
While root-b’s content will work for root-a, the reverse is not true.
As I said, maybe not that elegant when you think big sets; it should however, strictly answer what I think you asked and may give you pointers for other approaches.