'Allow different maxOccurs inside unbounded choice via XSD

XML:

<?xml version="1.0" encoding="UTF-8"?>
    <Credits>
         <Director>Movie</Director>
         <Director>Movie</Director>
         <Director>Movie</Director>
         <Producer />
         <Producer />
         <Actor>Jules Verne</Actor>
         <Producer />
         <Actor>Jules Verne</Actor>
         <Actor>Jules Verne</Actor>
</Credits>

XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="Credits">
        <xs:complexType>
            <xs:choice maxOccurs="unbounded">
                <xs:element name="Director" type="xs:string" />
                <xs:element name="Producer" type="xs:string" />
                <xs:element name="Actor" type="xs:string" />
                <xs:element name="Writer" type="xs:string" />
            </xs:choice>
        </xs:complexType>
    </xs:element>
</xs:schema>

How can I define XSD to restrict Actor to maxOccurs 1 and Writer to maxOccurs as 5 and rest as unbounded? Order of elements can vary.



Solution 1:[1]

In XSD 1.0, it's for practical purposes impossible (it can be done in principle by defining all possible combinations, but that's absurdly complex).

In XSD 1.1 you can use xsd:any with maxOccurs values on each of the particles.

Question: why do you want to do this? Why would you want to disallow movies with more than 5 writers? Is it some fundamental law of physics that movies can't have six writers?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael Kay