How to define a schema restriction that allows an enumeration value or pattern match?
regex, xsd
Solution
Turns out I need a `union`. Define the enumerated type as a separate type:
<xs:simpleType name="enumeration">
<xs:restriction base="xs:string">
<xs:enumeration value="one" />
<xs:enumeration value="two" />
</xs:restriction>
<xs:simpleType>
Then create the target type as an enumeration:
<xs:simpleType name="both">
<xs:union memberTypes="enumeration">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0..9]+" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
So now I get the pick list, or match the pattern. Exactly what I wanted!
Update: Can actually define both simple types as children of the `union` or via the `memberTypes` attribute.
Problem
I am defining a `simpleType` that has a `restriction` to either be a value from an `enumeration` or a value matching a `pattern`. I realize I can do it all from the `pattern` but I want to have the picklist that the `enumeration` provides. This is what I expected to be able to do: ``` <xs:simpleType name="both"> <xs:restriction base="xs:string"> <xs:enumeration value="one" /> <xs:enumeration value="two" /> <xs:pattern value="[0..9]+" /> </xs:restriction> <xs:simpleType> ``` But that fails since a value can't match both constraints. If I modify the pattern to allow for any enumerated value then it will fail it if only matches the pattern.