Adapting the structure of your document : Russian Doll « XML Schema « XML Tutorial






The result is instance documents such as: 
<?xml version="1.0"?>
<library>
  <book id="b1111111111" available="true">
    <title lang="en">Java</title>
    <isbn>1111111111</isbn>
    <authors>
      <author id="Client">
        <start>1922-11-26</start>
        <dead>2000-02-12</dead>
        <name>James</name>
      </author>
    </authors>
    <chapters>
      <chapter id="PP">
        <name>JButton</name>
        <qualification>Yes</qualification>
        <start>2005-08-22</start>
      </chapter>
      <chapter id="JTable">
        <start>2001-10-04</start>
        <name>JTable</name>
        <qualification>Yes</qualification>
      </chapter>
    </chapters>
  </book>
</library>

This instance document defined by a full schema, which could be: 
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="name" type="xs:token" />
  <xs:element name="qualification" type="xs:token" />
  <xs:element name="start" type="xs:date" />
  <xs:element name="dead" type="xs:date" />
  <xs:element name="isbn" type="xs:NMTOKEN" />
  <xs:attribute name="id" type="xs:ID" />
  <xs:attribute name="available" type="xs:boolean" />
  <xs:attribute name="lang" type="xs:language" />
  <xs:element name="title">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:token">
          <xs:attribute ref="lang" />
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
  <xs:element name="library">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="book" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="authors">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="author" minOccurs="0"
          maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="author">
    <xs:complexType>
      <xs:all>
        <xs:element ref="name" />
        <xs:element ref="start" />
        <xs:element ref="dead" minOccurs="0" />
      </xs:all>
      <xs:attribute ref="id" />
    </xs:complexType>
  </xs:element>
  <xs:element name="book">
    <xs:complexType>
      <xs:all>
        <xs:element ref="isbn" />
        <xs:element ref="title" />
        <xs:element ref="authors" />
        <xs:element ref="chapters" />
      </xs:all>
      <xs:attribute ref="id" />
      <xs:attribute ref="available" />
    </xs:complexType>
  </xs:element>
  <xs:element name="chapters">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="chapter" minOccurs="0"
          maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="chapter">
    <xs:complexType>
      <xs:all>
        <xs:element ref="name" />
        <xs:element ref="start" />
        <xs:element ref="qualification" />
      </xs:all>
      <xs:attribute ref="id" />
    </xs:complexType>
  </xs:element>
</xs:schema>








3.97.Russian Doll
3.97.1.Russian Doll and Object-Oriented Design
3.97.2.Russian Doll design nest the local element declaration within other schema component
3.97.3.Russian doll type element
3.97.4.Adapting the structure of your document
3.97.5.A book element of our library