(Mark Constant) writes:
> All I want to do is have a xml file like this
> [example elided]
>
> I try something like the schema below but this schema doesn't work.
> With this schema it is looking for a xml file like this. I want to be
> able to add as many Movie or PS2 elements in any order without errors.
>
> [example with single Movie and single PS2 element]
>
> ...
> <xs:element name="Entertainment">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="Movie" type="Information"></xs:element>
> <xs:element name="PS2" type="Information" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
Here's your problem: you are telling the schema processor that what
you want in an Entertainment element is a sequence consisting of
exactly one Movie element and exactly one PS2 element, in order.
You can use minOccurs and maxOccurs attributes on the xs:sequence or
xs:element elements to specify that more than one element can occur.
If we just specify maxOccurs="unbounded" on the two elements, we allow
any positive number of Movie elements, followed by any positive number
of PS2 elements:
<xs:complexType>
<xs:sequence>
<xs:element name="Movie" type="Information" maxOccurs="unbounded"/>
<xs:element name="PS2" type="Information" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
If you want to allow Entertainment elements without Movie elements
or PS2 elements, you can also add minOccurs="0" to the xs:element
elements.
Since you want to allow the Movie and PS2 elements to occur in any
order, however, you really need to change something else, too. One
way is to allow the sequence to repeat:
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="Movie" type="Information"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="PS2" type="Information"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
Note that since the sequence can repeat, the maxOccurs attributes on
the xs:element elements are no longer necessary and can be removed.
It is probably more usual, however, to express 'any number of Movie or
PS2 elements, in any order' not as a repeating sequence but as a
repeating choice, thus:
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Movie" type="Information"/>
<xs:element name="PS2" type="Information"/>
</xs:choice>
</xs:complexType>
I hope this helps.
-C. M. Sperberg-McQueen
World Wide Web Consortium