Allowing Elements to Appear in Any Order : all « XML Schema « XML Tutorial






The members of an 'all' group may appear once or not at all, in any order.
The minOccurs and maxOccurs attributes may only be set to 0 or 1.
An all group can only contain individual element declarations or references, not other groups. 
An all group can only be contained either a complex type definition or a named group definition.

File: Schema.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.java2s.com" 
  xmlns="http://www.java2s.com"
  elementFormDefault="qualified">

    <xsd:element name="subspecies" type="subspeciesType"/>

  <xsd:complexType name="subspeciesType">
    <xsd:all>
      <xsd:element name="region" type="xsd:string" minOccurs="0" />
      <xsd:element name="population" type="xsd:string" />
    </xsd:all>
  </xsd:complexType>
</xsd:schema>


File: Data.xml

<?xml version="1.0"?>
<subspecies xmlns="http://www.java2s.com">
  <population>3159</population>
  <region>India</region>
</subspecies>








3.61.all
3.61.1.Allowing Elements to Appear in Any Order
3.61.2. Declarations