Hi
I've got this problem and I can't for the life of me find a simple solution.
I am trying to codify a list of operating systems, where the XML file contains a list of the OSes that a given person has. There is a fixed list of OSes (XP, Vista, Win7, OSX and Ubuntu).
I have the following piece of XML
<operatingSystems>
<operatingSystem name="Windows XP" />
<operatingSystem name="Windows Vista" />
<operatingSystem name="Windows 7" />
<operatingSystem name="OS X" />
<operatingSystem name="Ubuntu Linux" />
</operatingSystems>
The <operatingSystems>
element can contain 0 or more of the operating systems listed.
So valid examples would be:
<operatingSystems>
<operatingSystem name="Windows XP" />
<operatingSystem name="OS X" />
<operatingSystem name="Ubuntu Linux" />
</operatingSystems>
or
<operatingSystems />
I am trying to write an XSD schema to validate this. My questions is what is the best way to go about validating that the <operatingSystems>
element only contains child <operatingSystem>
elements where the name is from the given set and that each name element does not appear more than once.
Invalid examples would be:
<operatingSystems>
<operatingSystem name="OS X" />
<operatingSystem name="OS X" />
<operatingSystem name="Ubuntu Linux" />
</operatingSystems>
or
<operatingSystems>
<operatingSystem name="Sun Solaris" />
</operatingSystems>
Ive tried this:
<element name="operatingSystems">
<complexType>
<sequence>
<element name="operatingSystem" minOccurs="0" maxOccurs="1">
<complexType>
<attribute name="name" fixed="Windows XP" />
</complexType>
</element>
<element name="operatingSystem" minOccurs="0" maxOccurs="1">
<complexType>
<attribute name="name" fixed="Windows Vista" />
</complexType>
</element>
.......
</sequence>
</complexType>
</element>
but it ingores the fact that minOccurs is 0 and will complain if any element operating system is missing.
Any help would be appreciated.
Thanks