In additions to primitives, XML schema of course allows to define complex types, like structures. There are two kinds of complex types: a sequence and a choice. While sequence represents a set of child elements present at the same time, choice can contain only one of them. We use in our definition sequence-type to define the content of purchase order:

<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="purchase-order"> ////////////// our purchase-order is a complex of type sequence: <xs:complexType> <xs:sequence> ////////////// order originator is alseo described as sequence of one element: <xs:element name="purchased-by"> <xs:complexType> <xs:sequence> <xs:element name="address" type="xs:string"/> </xs:sequence> ... </xs:complexType> </xs:element> ////////////// the items represents a collection: <xs:element name="order-items"> <xs:complexType> <xs:sequence> <xs:element name="item" maxOccurs="unbounded"> <xs:complexType> ... <xs:attribute name="code" type="xs:integer"/> ... </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> ... </xs:complexType> </xs:element> </xs:schema>  
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="purchase-order"> <xs:complexType> <xs:sequence> ... <xs:element name="order-items"> <xs:complexType> <xs:sequence> ////////////// here we refer an element declared somewhere late: <xs:element ref="item" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> ... </xs:sequence> ... </xs:complexType> </xs:element> ////////////// we declare all shared elements outside the root one: <xs:element name="item"> <xs:complexType> ... </xs:complexType> </xs:element> </xs:schema> 
 <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="purchase-order">
  <xs:complexType>
    <xs:sequence>
      ...
      <xs:element name="order-items">
      <xs:complexType>
          <xs:sequence>

////////////// here we refer an element declared somewhere late:

            <xs:element ref="item" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      ...
    </xs:sequence>
    ...
  </xs:complexType>
  </xs:element>

////////////// we declare all shared elements outside the root one:

  <xs:element name="item">
  <xs:complexType>
    ...
  </xs:complexType>
  </xs:element>
</xs:schema>