Suppose I have the following XSD file :
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="PACIDemoSignedDoc" type="PACIDemoSignedDocType" />
<xs:complexType name="PACIDemoSignedDocType">
<xs:all>
<xs:element name="OwnerEnglishName" type="OwnerEnglishNameType" />
</xs:all>
</xs:complexType>
<xs:complexType name="OwnerEnglishNameType">
<xs:simpleContent>
<xs:restriction base="NameType">
<xs:enumeration value="John"/>
<xs:enumeration value="Jack"/>
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="NameType">
<xs:simpleContent>
<xs:extension base="xs:string"/>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
My question is, where should I add the attributes minOccurs and maxOccurs for the element "OwnerEnglishName" ? I want to keep xs:all as I want to avoid having to order my XML file in sequence but it prohibits me from adding the Occurs directly in the <xs:element name="OwnerEnglishName" type="OwnerEnglishNameType" />
line...
I'm also guessing I can't add the Occur attributes inside OwnerEnglishNameType, anyone have any idea ?
Okay, I have solved my problem, here's the answer if others have the same problem :
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" targetNamespace="test" xmlns="test" elementFormDefault="qualified" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="animal" type="AnimalType" />
<xs:complexType name="AnimalType">
<xs:all>
<xs:element name="cats" type="Cats" />
</xs:all>
</xs:complexType>
<xs:simpleType name="CatType">
<xs:restriction base="xs:string">
<xs:enumeration value="John"/>
<xs:enumeration value="Jack"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="Cats">
<xs:sequence>
<xs:element maxOccurs="5" minOccurs="2" name="cat" type="Cat"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Cat">
<xs:simpleContent>
<xs:extension base="CatType"/>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
which validates the following xml :
<?xml version="1.0" encoding="UTF-8"?>
<animal xmlns="d" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test schema.xsd">
<cats>
<cat>John</cat>
<cat>Jack</cat>
</cats>
</animal>
I have successfully bypassed the Occurs restriction of xs:all by adding child elements following xs:sequence.