I'm creating an XSD where one of the elements needs to be either empty, or a value from an enumeration:
<xs:element name="MyElement" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="A" />
<xs:enumeration value="B" />
<xs:enumeration value="C" />
</xs:restriction>
</xs:simpleType>
</xs:element>
I had hoped that by setting the nillable attribute to true, it would allow A, B, C or an empty value:
<MyElement></MyElement>
But apparently that is not valid:
The Enumeration constraint failed.
I've also tried to explicitly add the empty value to the enumeration:
<xs:enumeration value="" />
But no luck either:
The Enumeration constraint failed.
Currently, I'm using a pattern instead:
<xs:pattern value="[ABC]{0,1}" />
This works, but I find this is an awful way to go for such a simple requirement. Surely there must be something I can do to allow "anything from the enumeration or empty"? Oh and don't suggest setting minOccurs to 0, the tag has to be there at all times.