<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >

  <xsd:element name="DBFile" type="typeDBFile"/>
  <xsd:element name="assembly"  type="typeMultipleAssembly"/>
  <xsd:element name="registration"  type="MultipleRegis"/>
  <xsd:element name="transfer" type="typeTransfer"/>

  <xsd:complexType name="typeDBFile">
     <xsd:sequence>
        <xsd:element ref="registration" minOccurs="0"/>
	     <xsd:element ref="assembly" minOccurs="0"/>
        <xsd:element ref="transfer" minOccurs="0"/>
        <xsd:element ref="unit" minOccurs="0"/>
</xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="typeTransfer">
     <xsd:sequence>
        <xsd:element name="transferItem" type="SingleTransfer" maxOccurs="unbounded"/>
     </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="SingleTransfer">
     <xsd:sequence>
        <xsd:element name="info" type="TransferInfo" maxOccurs="1"/>
	<xsd:element name="batch" type="typeSequence" maxOccurs="1"/>
     </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="TransferInfo">
     <xsd:all>
        <xsd:element name="id" type="xsd:long" maxOccurs="1"/>
        <xsd:element name="receiver" type="xsd:string" maxOccurs="1"/>
        <xsd:element name="sender" type="xsd:string" maxOccurs="1"/>
        <xsd:element name="carrier" type="xsd:string" maxOccurs="1"/>
        <xsd:element name="issued" type="xsd:dateTime" maxOccurs="1"/>
        <xsd:element name="arrived" type="xsd:dateTime" minOccurs="0" maxOccurs="1"/>
        <xsd:element name="description" type="xsd:string" minOccurs="0" maxOccurs="1"/>
     </xsd:all>
  </xsd:complexType>

  <xsd:complexType name="typeMultipleAssembly">
    <xsd:sequence>
        <xsd:element name="assemblyItem" type="typeAssembly" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="typeAssembly">
    <xsd:sequence>
      <xsd:element ref="parent" maxOccurs="1"/>
      <xsd:element ref="subobject" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:element name="parent"    type="typeParent"/>
  <xsd:element name="subobject" type="typeSubobject"/>

  <xsd:complexType name="typeParent">
     <xsd:attribute name="id" type="xsd:long" use="required"/>
  </xsd:complexType>

  <xsd:complexType name="typeSubobject">
     <xsd:attribute name="id" type="xsd:long" use="required"/>
     <xsd:attribute name="position" type="xsd:int" use="required"/>
     <xsd:attribute name="faulty" type="xsd:boolean" use="required"/>
     <xsd:attribute name="action" type="xsd:string" use="required"/>
     <xsd:attribute name="date" type="xsd:dateTime" use="required"/>
  </xsd:complexType>

  <xsd:element name="type" type="xsd:string"/>
  <xsd:element name="name" type="xsd:string"/>
  <xsd:element name="date" type="xsd:dateTime"/>
  <xsd:element name="version" type="xsd:int" default="1"/>
  <xsd:element name="center" type="xsd:string"/>

  <xsd:complexType name="typeCommon">
    <xsd:all>
      <xsd:element ref="date" maxOccurs="1"/>
      <xsd:element ref="name" maxOccurs="1"/>
      <xsd:element ref="type" maxOccurs="1"/>
      <xsd:element ref="version" minOccurs="0" maxOccurs="1"/>
      <xsd:element ref="center" maxOccurs="1"/>
    </xsd:all>
  </xsd:complexType>

  <xsd:complexType name="typeSequence">
    <xsd:sequence>
      <xsd:element name="object" type="typeObjectFaulty" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="SingleRegis">
    <xsd:sequence>
       <xsd:element name="commonData" type="typeCommon" maxOccurs="1"/>
       <xsd:element name="objects" type="typeSequence" maxOccurs="1"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="MultipleRegis">
    <xsd:sequence>
        <xsd:element name="registrationItem" type="SingleRegis" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="typeObjectFaulty">
     <xsd:attribute name="id" type="xsd:long" use="required"/>
     <xsd:attribute name="faulty" type="xsd:boolean" use="required"/>
  </xsd:complexType>

  <xsd:element name="unit"                type="typeUnit"/>
  <xsd:element name="object"              type="typeObject"/>
  <xsd:element name="composite"           type="typeComposite"/>
  <xsd:element name="action_description"  type="typeAdescription"/>
  <xsd:element name="action"              type="typeAction"/>
  <xsd:element name="input"               type="typeInput"/>
  <xsd:element name="result"              type="typeResult"/>

  <xsd:complexType name="typeUnit">
    <xsd:sequence>
      <xsd:element ref="object"/>
      <xsd:element ref="composite" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="typeObject">
    <xsd:attribute name="id" type="xsd:long" use="required"/>
  </xsd:complexType>

  <xsd:complexType name="typeComposite">
    <xsd:sequence>
      <xsd:element ref="action_description"/>
      <xsd:element ref="composite" minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element ref="action" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="typeAdescription">
      <xsd:attribute name="name"        type="xsd:string" use="required"/>
      <xsd:attribute name="version"     type="xsd:string" use="required"/>
      <xsd:attribute name="object_name" type="xsd:string" use="required"/>
      <xsd:attribute name="object_type" type="xsd:string" use="optional"/>
      <xsd:attribute name="input_id"    type="xsd:long"   use="required"/>
      <xsd:attribute name="position_in_parent" type="xsd:int" use="optional"/>
  </xsd:complexType>

  <xsd:complexType name="typeAction">
    <xsd:sequence>
      <xsd:element ref="action_description"/>
      <xsd:element ref="input"  minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element ref="result" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="typeInput">
    <xsd:attribute name="name"  type="xsd:string" use="required"/>
    <xsd:attribute name="sub_object_id" type="xsd:long" use="optional"/>
    <xsd:attribute name="sub_object" type="xsd:string" use="optional"/>
		<xsd:attribute name="sub_oject_position" type="xsd:int" use="optional"/>
    <xsd:attribute name="value" type="xsd:string" use="required"/>
  </xsd:complexType>

  <xsd:complexType name="typeResult">
    <xsd:attribute name="name"  type="xsd:string" use="required"/>
    <xsd:attribute name="value" type="xsd:string" use="required"/>
  </xsd:complexType>

</xsd:schema>