I have an XML file and a corresponding XSD file.
In the XSD file I define a list attribute where the items in the list are part of an enumeration.
Here is an example of what I’m doing.
<xs:simpleType name="Colors">
<xs:list itemType="ColorEnum"/>
</xs:simpleType>
<xs:simpleType name="ColorEnum">
<xs:restriction base="xs:token">
<xs:enumeration value="Red"/>
<xs:enumeration value="Blue"/>
<xs:enumeration value="Green"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="Color">
<xs:complexType>
<xs:attribute name="ColorList" type="Colors" />
</xs:complexType>
</xs:element>
The XML would look something like this:
<Color ColorList="Red Blue Green"></Color>
Is there any way to make sure that the elements in the list are unique? For instance, is there any way to prevent Red from being in this list twice?
I think the only way is using
xsd:pattern. You want:This should enforce also the order. I mean you can’t provide the sequence “Blue Green Red”. Anyway it should be a starting point.
EDIT Very nasty:
EDIT
The number of combinations is given by the factorial of the total number of elements you use in the sequence. I hope you won’t exceed three elements then 🙂