<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http:///org.eclipse.emf.test.models/Customer"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
    xmlns:db="http:///org.eclipse.emf.test.models/Customer" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    
    
    <xsd:element name="customers" type="db:customersType"/>
    <xsd:complexType name="customersType" mixed="true">
        <xsd:sequence>
            <xsd:element form="qualified" name="customer" type="db:dbcustomer" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>
    
    
    <xsd:complexType name="dbcustomer" ecore:name="CustomerType">
        <xsd:sequence>
            <xsd:element name="name" type="xsd:string"/>
            <xsd:element name="address" type="db:addressType"/>
            <xsd:element name="creditCard" type="db:creditInfo"/>
            <xsd:element name="paymentDay" type="xsd:gDay" nillable="true"/>            
        </xsd:sequence>
        <xsd:attribute ref="db:ID" use="required"/>
    </xsd:complexType>

    <xsd:attribute name="ID" type="xsd:ID"/>
    
    <xsd:complexType name="creditInfo">
      <xsd:all>
      	<xsd:element name="holder" type="xsd:string"/>
        <xsd:element name="cc_number" type="xsd:integer"/>
        <xsd:element name="expireDate" type="xsd:gYearMonth"/>
      </xsd:all>
    </xsd:complexType>  
    
    <xsd:complexType name="addressType" abstract="true">
      <xsd:sequence>
        <xsd:element name="street" type="xsd:string"/>
        <xsd:element name="town" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
   
    <xsd:complexType name="USAddr">
        <xsd:complexContent>
          <xsd:extension base="db:addressType">
           <xsd:sequence>
            <xsd:element name="zip" type="db:zipUnion"/>
            <xsd:element name="state" type="xsd:string"/> 
           </xsd:sequence>           
        </xsd:extension>
      </xsd:complexContent>
    </xsd:complexType> 
    
    <xsd:complexType name="canadaAddr">
        <xsd:complexContent>
          <xsd:extension base="db:addressType">
           <xsd:sequence>
            <xsd:element name="zip" type="xsd:string"/>
            <xsd:element name="province" type="xsd:string"/>  
           </xsd:sequence>          
        </xsd:extension>
      </xsd:complexContent>
    </xsd:complexType> 

    <xsd:simpleType name="USState">
      <xsd:restriction base="xsd:string">
        <xsd:enumeration value="AK"/>
        <xsd:enumeration value="AL"/>
        <xsd:enumeration value="AR"/>
        <!-- and so on ... -->
      </xsd:restriction>
    </xsd:simpleType>
    
    <xsd:simpleType name="zipCodes">
  		<xsd:restriction base="xsd:integer">
    		<xsd:minInclusive value="10000"/>
    		<xsd:maxInclusive value="99999"/>
  		</xsd:restriction>
	</xsd:simpleType>

	<xsd:simpleType name="zipUnion">
  		<xsd:union memberTypes="db:USState db:zipCodes"/>
	</xsd:simpleType>


    
</xsd:schema>