Russian Doll and Object-Oriented Design : Russian Doll « XML Schema « XML Tutorial






The style of defining elements and attributes locally is often called the Russian doll design.
Since the definition of each element is embedded in the definition of its parent.  
Objects are created locally where they are needed as opposed to being created globally and cloned when we need them.


File: Data.xml
<?xml version="1.0"?>  
<library> 
  <book id="b01111111111" available="true"> 
    <isbn>1111111111</isbn> 
    <title lang="en">Java</title> 
    <author id="CMS"> 
      <name>Swing</name> 
      <start>1996-11-26</start> 
      <dead>2008-02-12</dead> 
    </author> 
    <chapter id="PP"> 
      <name>JButton</name> 
      <start>2001-08-22</start> 
      <qualification>Yes</qualification> 
    </chapter> 
  </book> 
</library> 

File: Schema.xsd

<?xml version="1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
  <xs:element name="library"> 
    <xs:complexType> 
      <xs:sequence> 
        <xs:element name="book" maxOccurs="unbounded"> 
          <xs:complexType> 
            <xs:sequence> 
              <xs:element name="isbn" type="xs:integer"/> 
              <xs:element name="title"> 
                <xs:complexType> 
                 <xs:simpleContent> 
                 <xs:extension base="xs:string"> 
                 <xs:attribute name="lang" type="xs:language"/> 
                 </xs:extension> 
                 </xs:simpleContent> 
                </xs:complexType> 
              </xs:element>  
              <xs:element name="author" minOccurs="0" 
                maxOccurs="unbounded"> 
                <xs:complexType> 
                 <xs:sequence> 
                 <xs:element name="name" type="xs:string"/> 
                 <xs:element name="start" type="xs:date"/> 
                 <xs:element name="dead" type="xs:date"/> 
                 </xs:sequence> 
                 <xs:attribute name="id" type="xs:ID"/> 
                </xs:complexType> 
              </xs:element>  
              <xs:element name="chapter" minOccurs="0" 
                maxOccurs="unbounded"> 
                <xs:complexType> 
                 <xs:sequence> 
                 <xs:element name="name" type="xs:string"/> 
                 <xs:element name="start" type="xs:date"/> 
                 <xs:element name="qualification" type="xs:string"/> 
                 </xs:sequence> 
                 <xs:attribute name="id" type="xs:ID"/> 
                </xs:complexType> 
              </xs:element> 
            </xs:sequence> 
            <xs:attribute name="id" type="xs:ID"/> 
            <xs:attribute name="available" type="xs:boolean"/> 
          </xs:complexType> 
        </xs:element> 
      </xs:sequence> 
    </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