Imagine a technology that offered you all the power of a DTD without the associated unpleasantness of those strange symbols and arcane commands. Sounds too good to be true? Say hello to XML Schema.
If a complex element contains child elements, these child element definitions appear nested within a <xsd:sequence> element. In the previous example, the elements nested within the "movie" container element are all simple elements; however, it's also possible to have nested complex elements, as in the following XML document:
In this case, the element "cast", which contains child elements of its own, is
nested within the "movie" element, which is itself a complex element. The corresponding schema definition would look like this:
In case you're wondering, the "maxOccurs" attribute is used to specify the maximum
number of occurrences of the corresponding element (there's a corresponding "minOccurs" attribute to control the minimum number of occurrences). Both these attributes default to 1, unless they're explicitly assigned a value. And just incidentally, you can't achieve this level of precision with a DTD.
In this particular example, a value of "unbounded" for the "maxOccurs" attribute allows for an infinite number of "person" elements in the document instance.
It's also possible to make certain elements optional. In order to illustrate this, let's add a couple of new elements to the schema definition above - a "release_date" element of type "date", and a "rating" element of type "integer". And let's also make the "release_date" element optional, through judicious use of the "minOccurs" and "maxOccurs" attributes.