prev table of contents next

2.2.12.3 Content: An Unordered Set of Elements

Content consisting of a set of elements that may occur in any order within its parent XML element can be defined by using the schema element xsd:all. There is, however, a severe restriction: the maxOccurs may not have a value greater than 1. Here is the definition for an XML element describing the courses of a dinner which does not permit repetitions of any course, but you may omit all courses except for the main dish.

<xsd:complexType name="DinnerType">
  <xsd:all>
    <xsd:element name="Starter" type="xsd:string" minOccurs="0"/>
    <xsd:element name="Soup"    type="xsd:string" minOccurs="0"/>
    <xsd:element name="Entree"  type="xsd:string"/>
    <xsd:element name="Dessert" type="xsd:string" minOccurs="0"/>
  </xsd:all>
</xsd:complexType>
The generated Java conforms to the structure of a JavaBean:
public class LunchType {

    protected String starter;
    protected String soup;
    protected String entree;
    protected String dessert;

    public String getStarter() {
        return starter;
    }

    public void setStarter( String value ) {
        this.starter = value;
    }

    // ...(more getters and setters)
}
Here, the getters for the optional child elements may return null to distinguish "not present" from any possible value.


prev table of contents next