<?xml version = "1.0" encoding = "UTF-8"?>

<!-- Namespace Declarations in XMLSchema -->
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema"  version = "1.0">


<!-- Declaring global Elements -->
<xsd:element name = "FirstName" type = "xsd:string">
    <xsd:annotation>
     <xsd:documentation>First Name of the Person</xsd:documentation>
    </xsd:annotation>
</xsd:element>



<!-- Derived type MI by a restriction on the length of base type string -->
<xsd:element name = "MiddleInitial">

    <!-- A SimpleType (comprises of only one type of element - here string) -->
    <xsd:simpleType>
        <!-- Restriction -->
        <xsd:restriction base = "xsd:string">
           <xsd:maxLength value = "1"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>


<!-- ComplexType Element (comprises of multiple types of elements) -->
<xsd:complexType name = "Staff">

      <!-- sequence (ordered set) of elements -->
      <xsd:sequence>

         <!-- Declaring a local Element -->
         <xsd:element name = "LastName" type = "xsd:string">
            <xsd:annotation>
               <xsd:documentation>Last Name of the Person</xsd:documentation>
            </xsd:annotation>
         </xsd:element>

         <!-- Referencing global elements -->
         <xsd:element ref="FName" />
         <xsd:element ref="MI" />

         <!-- Declaring local Elements -->
         <xsd:element name = "EMail" type = "xsd:string" />
         <xsd:element name = "HomePage" type = "xsd:anyURI" />
         <xsd:element name = "TelNo" type = "xsd:string" />
         <xsd:element name = "Group" type = "xsd:string" maxOccurs="unbounded"/>

         <!-- Restriction on the range of values of OfficeNo -->
         <xsd:element name = "OfficeNo">
            <xsd:simpleType>
               <xsd:restriction base = "xsd:nonNegativeInteger">
                   <xsd:maxInclusive value = "1300"/>
                   <xsd:minInclusive value = "100"/>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>

      </xsd:sequence>
</xsd:complexType>


<xsd:complexType name = "Researcher">
   <xsd:complexContent>
      <!-- Extension of Previous Type Staff -->
      <xsd:extension base = "Staff">
         <xsd:sequence>
            <xsd:element name = "Project" type = "xsd:string" maxOccurs = "unbounded"/>
            <xsd:element name = "Papers" type = "xsd:string" minOccurs = "0" maxOccurs = "unbounded"/>
         </xsd:sequence>
      </xsd:extension>
   </xsd:complexContent>
</xsd:complexType>

<!-- Further Extensions to Researcher -->
<xsd:complexType name = "ISIResearchStaff">
   <xsd:complexContent>
      <!-- Extension of Previous Type Staff -->
      <xsd:extension base = "Researcher">
         <xsd:sequence>
            <xsd:element name = "NumProjPrincipal" type = "xsd:integer" />
         </xsd:sequence>
      </xsd:extension>
   </xsd:complexContent>
</xsd:complexType>
<!-- Declaring Global Element 'Major' -->
<xsd:element name = "Major">
   <xsd:simpleType>
      <!-- Restricting the values to a set of value using 'enumeration' -->
      <xsd:restriction base = "xsd:string">
         <xsd:enumeration value = "CS"/>
         <xsd:enumeration value = "CSCN"/>
         <xsd:enumeration value = "EE"/>
         <xsd:enumeration value = "EECN"/>
      </xsd:restriction>
   </xsd:simpleType>
</xsd:element>



<!-- Declaring Global Element 'DegreeObjective'
   - using enumeration -->

<xsd:element name = "DegreeObjective">
   <xsd:simpleType>
      <xsd:restriction base = "xsd:string">
         <xsd:enumeration value = "MS"/>
         <xsd:enumeration value = "PhD"/>
      </xsd:restriction>
   </xsd:simpleType>
</xsd:element>


<xsd:complexType name = "GRA">
   <xsd:complexContent>
   <xsd:extension base = "Researcher">
      <xsd:sequence>
         <xsd:element ref="Major" />
         <xsd:element ref="DegreeObjective" />
      </xsd:sequence>
   </xsd:extension>
   </xsd:complexContent>
</xsd:complexType>


<xsd:complexType name = "Intern">
   <xsd:complexContent>
   <xsd:extension base = "Researcher">
     <xsd:sequence>
        <xsd:element name = "College" type = "xsd:string"/>
        <xsd:element name = "StartDate" type = "xsd:date"/>
        <xsd:element name = "EndDate" type = "xsd:date"/>
     </xsd:sequence>
   </xsd:extension>
   </xsd:extension>
   </xsd:complexContent>
</xsd:complexType>


<xsd:complexType name = "Admin">
   <xsd:complexContent>
   <xsd:extension base = "Staff">
     <xsd:sequence>
       <xsd:element name = "AdminGroup" type = "xsd:string"/>
     </xsd:sequence>
   </xsd:extension>
   </xsd:complexContent>
</xsd:complexType>


<xsd:complexType name = "ProjAssistant">
   <xsd:complexContent>
   <xsd:extension base = "Admin">
     <xsd:sequence>
       <xsd:element name = "Project" type = "xsd:string"/>
     </xsd:sequence>
   </xsd:extension>
   </xsd:complexContent>
</xsd:complexType>


<xsd:complexType name = "Coordinator">
   <xsd:complexContent>
     <xsd:extension base = "Admin"/>
   </xsd:complexContent>
</xsd:complexType>


<xsd:element name = "Coordinator" type = "Coordinator"/>
<xsd:element name = "ProjAssistant" type = "ProjAssistant"/>
<xsd:element name = "Intern" type = "Intern"/>
<xsd:element name = "GRA" type = "GRA"/>
<xsd:element name = "ProjLeader" type = "ISIResearchStaff"/>
<xsd:element name = "SRSci" type = "ISIResearchStaff"/>

<xsd:element name = "ISIPeople">
   <xsd:complexType>
   <!-- ISIPeople can be one of the following -->
   <xsd:choice minOccurs = "0" maxOccurs = "unbounded">
      <xsd:element ref = "ProjLeader"/>
      <xsd:element ref = "SRSci"/>
      <xsd:element ref = "GRA"/>
      <xsd:element ref = "Intern"/>
      <xsd:element ref = "Coordinator"/>
      <xsd:element ref = "ProjAssistant"/>
     </xsd:choice>
   </xsd:complexType>
</xsd:element>
<!-- Just Examples to illustrate a few points -->
<!-- UNION -- (a definition of maxOccurs as either a +'ve integer or 'unbounded' >
  <xsd:simpleType name="maxOccurs">
    <xsd:union>
      <xsd:simpleType>
        <xsd:restriction base='nonNegativeInteger'/>
      </xsd:simpleType>
      <xsd:simpleType>
        <xsd:restriction base='string'>
          <xsd:enumeration value='unbounded'/>
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:union>
  </xsd:simpleType>

</xsd:schema>