<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:annotation>
    <xsd:documentation xml:lang="en">
      eID XML schema.
      Copyright(c) 2015-2018 FedICT.

      This XSD defines the XML data format of the XML ".eid" files as
      generated by the v4 eID viewer. For backwards compatibility
      reasons, the eID viewer will also read older file formats that are
      not defined by this document. These files do not have a documented
      file format, but they can be converted to this XML format by way
      of the eID viewer.

      Note that due to limitations in the XSD specification, it was
      necessary to list certain items (such as the "middlename" element)
      in the top level in order to be able to mark them as optional
      where they are actually used. A side effect of this is that the
      XSD will also validate such elements if they were the toplevel
      element, which is not what is intended and which would not be
      accepted by the eID viewer.

      While every effort has been made to ensure this specification is
      free of errors, no guarantees are made as to its correctness.
      Whenever a discrepancy exists between this specification and the
      actual implementation in the eID viewer, the eID viewer takes
      precedence.
    </xsd:documentation>
  </xsd:annotation>
  <xsd:element name="eid" type="eidType" />
  <xsd:complexType name="eidType">
    <xsd:sequence>
      <xsd:element name="identity" type="identityType" />
      <xsd:element name="card" type="cardType" />
      <xsd:element name="address" type="addressType" />
      <xsd:element name="certificates" type="certificatesType" />
    </xsd:sequence>
    <xsd:attribute name="version" use="optional">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
          <xsd:enumeration value="4.1" />
          <xsd:enumeration value="4.2" />
          <xsd:enumeration value="4.3" />
	  <xsd:enumeration value="4.4" />
	  <xsd:enumeration value="4.5" />
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:attribute>
	<xsd:attribute name="graphpersoversion" use="optional">
      <xsd:simpleType>
		<xsd:restriction base="xsd:hexBinary">
			<xsd:length value="1" fixed="true" />
		</xsd:restriction>
      </xsd:simpleType>
    </xsd:attribute>
  </xsd:complexType>
  <xsd:element name="middlenames" type="xsd:string" />
  <xsd:element name="workpermit" type="workpermitType" />
  <xsd:element name="brexit" type="brexitType" />
  <xsd:element name="cardA" type="cardAType" />
  <xsd:complexType name="identityType">
    <xsd:sequence>
      <xsd:element name="name" type="xsd:string" />
      <xsd:element name="firstname" type="xsd:string" />
      <xsd:element ref="middlenames" minOccurs="0" />
      <xsd:element name="nationality" type="xsd:string" />
      <xsd:element name="placeofbirth" type="xsd:string" />
      <xsd:element name="photo" type="xsd:base64Binary" />
    </xsd:sequence>
    <xsd:attribute name="nationalnumber" type="nnType" use="required"/>
    <xsd:attribute name="dateofbirth" type="eidDateType" use="required"/>
    <xsd:attribute name="gender" type="genderType" use="required"/>
    <xsd:attribute name="noblecondition" type="xsd:string" use="optional" />
    <xsd:attribute name="specialstatus" type="specType" use="optional" />
    <xsd:attribute name="duplicate" type="dupType" use="optional" />
    <xsd:attribute name="memberoffamily" type="xsd:boolean" use="optional" />
    <xsd:attribute name="dateandcountryofprotection" type="dcpType" use="optional"/>
  </xsd:complexType>
  <xsd:simpleType name="nnType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\d{11}" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="eidDateType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\d{8}" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="genderType">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="male" />
      <xsd:enumeration value="female" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:complexType name="workpermitType">
    <xsd:attribute name="mention" use="required">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
	  <xsd:enumeration value="unlimited" />
	  <xsd:enumeration value="limited" />
	  <xsd:enumeration value="no" />
	  <xsd:enumeration value="seasonal worker" />
	</xsd:restriction>
      </xsd:simpleType>
    </xsd:attribute>
    <xsd:attribute name="vat1" type="vatType" use="optional" />
    <xsd:attribute name="vat2" type="vatType" use="optional" />
    <xsd:attribute name="regionalfile" use="optional">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
          <xsd:maxLength value="18" />
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:attribute>
  </xsd:complexType>
  <xsd:complexType name="brexitType">
    <xsd:attribute name="mention1" use="required">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
          <xsd:enumeration value="Article 18(1) Agreement" />
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:attribute>
    <xsd:attribute name="mention2" use="optional">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
	  <xsd:enumeration value="Permanent stay" />
	</xsd:restriction>
      </xsd:simpleType>
    </xsd:attribute>
  </xsd:complexType>
  <xsd:complexType name="cardAType">
    <xsd:attribute name="mentions1" use="optional">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
          <xsd:enumeration value="Seasonal worker" />
		  <xsd:enumeration value="Student" />
		  <xsd:enumeration value="Pupil" />
		  <xsd:enumeration value="Intern" />
		  <xsd:enumeration value="Volunteer" />
		  <xsd:enumeration value="Au pair" />
		  <xsd:enumeration value="Researcher mobility"/>
		  <xsd:enumeration value="Job search" />	  
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:attribute>
    <xsd:attribute name="mentions2" use="optional">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
	  <xsd:enumeration value="Mobility program" />
	</xsd:restriction>
      </xsd:simpleType>
    </xsd:attribute>
  </xsd:complexType>
  <xsd:simpleType name="specType">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="NO_STATUS" />
      <xsd:enumeration value="WHITE_CANE" />
      <xsd:enumeration value="EXTENDED_MINORITY" />
      <xsd:enumeration value="WHITE_CANE_EXTENDED_MINORITY" />
      <xsd:enumeration value="YELLOW_CANE" />
      <xsd:enumeration value="YELLOW_CANE_EXTENDED_MINORITY" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="dupType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\d{2}" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:complexType name="cardType">
    <xsd:sequence>
      <xsd:element name="deliverymunicipality" />
      <xsd:element ref="workpermit" minOccurs="0" />
	  <xsd:element ref="brexit" minOccurs="0" />
	  <xsd:element ref="cardA" minOccurs="0" />
    </xsd:sequence>
    <xsd:attribute name="documenttype" type="doctypeType" use="required"/>
    <xsd:attribute name="cardnumber" type="cardnumType" use="required"/>
    <xsd:attribute name="chipnumber" type="chipnumType" use="required"/>
    <xsd:attribute name="validitydatebegin" type="eidDateType" use="required"/>
    <xsd:attribute name="validitydateend" type="eidDateType" use="required"/>
  </xsd:complexType>
  <xsd:simpleType name="doctypeType">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="belgian_citizen" />
      <xsd:enumeration value="kids_card" />
      <xsd:enumeration value="bootstrap_card" />
      <xsd:enumeration value="habilitation_card" />
      <xsd:enumeration value="foreigner_a" />
      <xsd:enumeration value="foreigner_b" />
      <xsd:enumeration value="foreigner_c" />
      <xsd:enumeration value="foreigner_d" />
      <xsd:enumeration value="foreigner_e" />
      <xsd:enumeration value="foreigner_e_plus" />
      <xsd:enumeration value="foreigner_f" />
      <xsd:enumeration value="foreigner_f_plus" />
      <xsd:enumeration value="european_blue_card_h" />
      <xsd:enumeration value="ict_i" />
      <xsd:enumeration value="mobile_ict_j" />
      <xsd:enumeration value="foreigner_m" />
      <xsd:enumeration value="foreigner_n" />
      <xsd:enumeration value="foreigner_eu" />
      <xsd:enumeration value="foreigner_eu_plus" />
      <xsd:enumeration value="foreigner_k" />
      <xsd:enumeration value="foreigner_l" />
      <xsd:enumeration value="foreigner_A" />
      <xsd:enumeration value="foreigner_B" />
      <xsd:enumeration value="foreigner_F" />
      <xsd:enumeration value="foreigner_F_plus" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="cardnumType">
    <xsd:restriction base="xsd:string">
      <xsd:maxLength value="12" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="chipnumType">
    <xsd:restriction base="xsd:hexBinary">
      <xsd:length value="16" fixed="true" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:complexType name="addressType">
    <xsd:sequence>
      <xsd:element name="streetandnumber" type="xsd:string" />
      <xsd:element name="zip" type="xsd:string" />
      <xsd:element name="municipality" type="xsd:string" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:element name="authentication" type="xsd:base64Binary" />
  <xsd:element name="signing" type="xsd:base64Binary" />
  <xsd:complexType name="certificatesType">
    <xsd:sequence>
      <xsd:element name="root" type="xsd:base64Binary" />
      <xsd:element name="citizenca" type="xsd:base64Binary" />
      <xsd:element ref="authentication" minOccurs="0" />
      <xsd:element ref="signing" minOccurs="0" />
      <xsd:element name="rrn" type="xsd:base64Binary" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:simpleType name="dcpType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\d{8}[a-zA-Z0-9]{2}" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="vatType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\d{10}" />
    </xsd:restriction>
  </xsd:simpleType>
</xsd:schema>
