I have the following XSD sample
If you can loose the comma (not supported as a separator in XSD), and be content with whitespaces, then this is your solution:
<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="days">
<xsd:simpleType>
<xsd:list>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Monday"/>
<xsd:enumeration value="Tuesday"/>
<xsd:enumeration value="Wednesday"/>
<xsd:enumeration value="Thursday"/>
<xsd:enumeration value="Friday"/>
<xsd:enumeration value="Saturday"/>
<xsd:enumeration value="Sunday"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:list>
</xsd:simpleType>
</xsd:element>
</xsd:schema>
You're basically using a list, therefore something like this would be perfectly valid:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<days xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Monday Tuesday Wednesday </days>
To be proactive here... if, for example, one might want to ensure uniqueness of the values, then this cannot be enforced in XSD.
Seems like your use case is better handled with the use of Regular Expressions since you mentioned user input:
.*day(,.*day)*
You can replace *.day
with (Monday|Tuesday|...)
.
as stated above but to show explicitly:
<xs:simpleType name="DayOfWeek">
<xs:restriction base="xs:string">
<xs:pattern value="(Mon|Tues|Wed)(,(Mon|Tues|Wed))*"/>
</xs:restriction>
</xs:simpleType>
This expression includes the values you want plus This also allows "Mon,Mon,Mon,Tues,Mon" which may not be a big problem depending on how you use the data after you read it. I mean if they are flags then: Mon, Mon, Mon isn't a problem.