Today, I want to a little about how content models are defined in complex types. These are important concepts in not only creating schemas and instances that are valid against the schemas, but will also help in understanding static typing and static typing errors within XQuery (this will be topic in a couple of posts).
The important thing to understand about complex types is that they define content models that contain elements and attributes. The structure and potentially the order of elements within a complex type is the content model. XSD allows you group your content that specifies if all the elements are required and should appear in order in a valid instance. These content groups and elements within these content groups can be specified as optional and may even repeat an arbitrary number of times.
A sequence group specifies that the content should all be present and in order. A choice group specifies that one item in the group should be present. An all group specifies that all the content should be present, but in any order. Sequences and choice groups can be nested within each other. An all content group can only be at the top of a complex content model.
Here is an example:
<
Notice that I can specify minOccurs and maxOccurs attributes on model groups and elements. For the complex type "foo", the sequence can be repeat an arbitrary number of times (maxOccurs="unbounded". And the element bar within this sequence does not have to appear at all within one instance of the sequence (minOccurs="0"). The same goes for the choice model group.