<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="TWSExchange">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="head" maxOccurs="1"/>
        <xs:element ref="goods" maxOccurs="1"/>
        <xs:element ref="process" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <!-- Element HEAD -->
  <xs:element name="head">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="sender" minOccurs="1"/>
        <xs:element ref="receiver" minOccurs="1"/>
        <xs:element ref="message_type" minOccurs="1"/>
        <xs:element ref="number_of_packages" minOccurs="0">
          <xs:annotation>
            <xs:documentation>Element is depreceated</xs:documentation>
          </xs:annotation>
        </xs:element>
        <xs:element ref="reference" minOccurs="1"/>
        <xs:element ref="export_origin" minOccurs="0"/>
        <xs:element ref="erp_reference" minOccurs="1"/>
        <xs:element ref="ucr_reference" minOccurs="0"/>
        <xs:element ref="created_date_time" minOccurs="1"/>
        <xs:element ref="vehicle_id" minOccurs="0"/>
        <xs:element ref="vehicle_origin" minOccurs="0"/>
        <xs:element ref="vehicle_phone" minOccurs="0"/>
        <xs:element ref="customs_office" minOccurs="0"/>
        <xs:element ref="delivery_conditions" minOccurs="0"/>
        <xs:element ref="goods_locale_code" minOccurs="0"/>
        <xs:element ref="goods_locale_type" minOccurs="0"/>
        <xs:element ref="guarantee" minOccurs="0"/>
        
        <xs:element ref="no_of_packages" minOccurs="0">
          <xs:annotation>
            <xs:documentation>Element is depreceated</xs:documentation>
          </xs:annotation>
        </xs:element>

        <xs:element ref="packages_type" minOccurs="0">
          <xs:annotation>
            <xs:documentation>Element is depreceated</xs:documentation>
          </xs:annotation>
        </xs:element>
        
        <xs:element ref="address_f2" minOccurs="0">
          <xs:annotation>
            <xs:documentation>Element is depreceated</xs:documentation>
          </xs:annotation>
        </xs:element>
        
        <xs:element ref="address_f8" minOccurs="0">
          <xs:annotation>
            <xs:documentation>Element is depreceated</xs:documentation>
          </xs:annotation>
        </xs:element>

        <xs:element ref="address_f14" minOccurs="0">
          <xs:annotation>
            <xs:documentation>Element is depreceated</xs:documentation>
          </xs:annotation>
        </xs:element>

        <xs:element ref="procedure_code" minOccurs="0"/>
        <xs:element ref="invoice_reference" minOccurs="0"/>
        <xs:element ref="invoice_total" minOccurs="0"/>
        <xs:element ref="invoice_date" minOccurs="0"/>
        <xs:element ref="create_declaration" minOccurs="0"/>
        <xs:element ref="invoice_currency" minOccurs="0"/>
        <xs:element ref="export_destination" minOccurs="0"/>
        <xs:element ref="destination" minOccurs="0"/>
        <xs:element ref="total_quantity" minOccurs="0"/>
        
        <xs:element ref="incomming_goods_number" minOccurs="0">
          <xs:annotation>
            <xs:documentation>Element is depreceated, use incoming_goods_number</xs:documentation>
          </xs:annotation>
        </xs:element>

        <xs:element ref="incoming_goods_number" minOccurs="0"/>
        <xs:element ref="vat_number" minOccurs="0"/>
        <xs:element ref="eori" minOccurs="0"/>
        <xs:element ref="head_note" minOccurs="0"/>
        <xs:element ref="order_type" minOccurs="0"/>
        <xs:element ref="order_ref_1" minOccurs="0"/>
        <xs:element ref="order_ref_2" minOccurs="0"/>
        <xs:element ref="transport_type_at_border" minOccurs="0"/>
        <xs:element ref="transport_type_domestic" minOccurs="0"/>
        <xs:element ref="transport_means" minOccurs="0"/>
        <xs:element ref="container" minOccurs="0"/>
        <xs:element ref="goods_location" minOccurs="0"/>
        <xs:element ref="previousdocuments" minOccurs="0"/>
        <xs:element ref="authorisation_holder" minOccurs="0"/>
        <xs:element ref="test_flag" minOccurs="0"/>
        <xs:element ref="estimated_time_of_arrival" minOccurs="0"/>
        <xs:element ref="declare_vat" minOccurs="0"/>
        <xs:element ref="nature_of_transaction" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="integration_data" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="actors" minOccurs="0"/>
        <xs:element ref="authorisations" minOccurs="0" maxOccurs="99"/>
        <xs:element ref="additional_information" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element ref="tradeterms" minOccurs="0"/>
        <xs:element ref="customsvaluation" minOccurs="0" maxOccurs="99"/>
        <xs:element ref="template" minOccurs="0" maxOccurs="10">
          <xs:annotation>
            <xs:documentation>Element is used for assigning special templates for declarations etc.</xs:documentation>
          </xs:annotation>
        </xs:element>
        <xs:element ref="consignmentroute" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
    <!-- Element HEAD def-->
  <xs:element name="sender" type="xs:string"/>
  <xs:element name="receiver" type="xs:string"/>
  <xs:element name="message_type" type="xs:string"/>
  <xs:element name="number_of_packages" type="xs:integer"/>
  <xs:element name="reference" type="xs:string"/>
  <xs:element name="export_origin" type="validatecountrycode"/>
  <xs:element name="erp_reference" type="xs:string"/>
  <xs:element name="created_date_time" type="xs:dateTime"/>
  <xs:element name="vehicle_id" type="xs:string"/>
  <xs:element name="vehicle_origin" type="xs:string"/>
  <xs:element name="vehicle_phone" type="xs:string"/>
  <xs:element name="customs_office" type="xs:string"/>
  <xs:element name="delivery_conditions" type="xs:string"/>
  <xs:element name="goods_locale_code" type="xs:string"/>
  <xs:element name="goods_locale_type" type="xs:string"/>
  <xs:element name="guarantee" type="xs:string"/>
  <xs:element name="no_of_packages" type="xs:integer"/>
  <xs:element name="packages_type" type="xs:string"/>
  <xs:element name="address_f2" type="xs:string"/>
  <xs:element name="address_f8" type="xs:string"/>
  <xs:element name="address_f14" type="xs:string"/>
  <xs:element name="invoice_reference" type="xs:string"/>
  <xs:element name="invoice_total" type="positivedecimalzero"/>
  <xs:element name="invoice_date" type="xs:dateTime"/>
  <xs:element name="create_declaration" type="xs:boolean"/>
  <xs:element name="invoice_currency" type="validatecurrency"/>
  <xs:element name="destination" type="xs:string"/>
  <xs:element name="export_destination" type="validatecountrycode"/>
  <xs:element name="total_quantity" type="xs:string"/>
  <xs:element name="incomming_goods_number" type="xs:string"/>
  <xs:element name="incoming_goods_number" type="xs:string"/>
  <xs:element name="vat_number" type="xs:string"/>
  <xs:element name="eori" type="xs:string"/>
  <xs:element name="head_note" type="xs:string"/>
  <xs:element name="order_type" type="xs:string"/>
  <xs:element name="order_ref_1" type="xs:string"/>
  <xs:element name="order_ref_2" type="xs:string"/>
  <xs:element name="transport_type_at_border" type="xs:string"/>
  <xs:element name="transport_type_domestic" type="xs:string"/>
  <xs:element name="declare_vat" type="xs:boolean"/>
  <xs:element name="nature_of_transaction" type="xs:positiveInteger"/>



  <!-- Element GOODS -->
  <xs:element name="goods">
    <xs:complexType>
      <xs:sequence maxOccurs="unbounded">
        <xs:element ref="row"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="row">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="description" minOccurs="1"/>
        <xs:element ref="goods_id_se" minOccurs="0"/>
        <xs:element ref="goods_id_no" minOccurs="0"/>
        <xs:element ref="goods_origin" minOccurs="1"/>
        <xs:element ref="gross_weight" minOccurs="0"/>
        <xs:element ref="benefit" minOccurs="0"/>
        <xs:element ref="net_weight" minOccurs="0"/>
        <xs:element ref="additional_unit_se" minOccurs="0"/>
        <xs:element ref="additional_unit_no" minOccurs="0"/>
        <xs:element ref="price_currency" minOccurs="0"/>
        <xs:element ref="price" minOccurs="0"/>
        <xs:element ref="freight_cost" minOccurs="0"/>
        <xs:element ref="certificate_type" minOccurs="0"/>
        <xs:element ref="certificate_reference" minOccurs="0"/>
        <xs:element ref="certificate_date_time" minOccurs="0"/>
        <xs:element ref="certificate_end_date_time" minOccurs="0"/>
        <xs:element ref="additional_certificate_type" minOccurs="0"/>
        <xs:element ref="additional_certificate_reference" minOccurs="0"/>
        <xs:element ref="additional_certificate_date_time" minOccurs="0"/>
        <xs:element ref="additional_certificate_end_date_time" minOccurs="0"/>
        <xs:element ref="certificate_quantity" minOccurs="0"/>
        <xs:element ref="textile_licence_number" minOccurs="0"/>
        <xs:element ref="textile_licence_amount" minOccurs="0"/>
        <xs:element ref="invoice_declaration" minOccurs="0"/>
        <xs:element ref="invocie_declaration" minOccurs="0"/>
        <xs:element ref="exchange_rate" minOccurs="0"/>
        <xs:element ref="vat_code" minOccurs="0"/>
        <xs:element ref="taxes" minOccurs="0"/>
        <xs:element ref="internal_reference" minOccurs="1"/>
        <xs:element ref="ucr_reference" minOccurs="0"/>
        <xs:element ref="alarm" minOccurs="0"/>
        <xs:element ref="additional_information" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element ref="no_of_packages" minOccurs="0"/>
        <xs:element ref="packages_type" minOccurs="0"/>
        <xs:element ref="packaging" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element ref="additional_reference" minOccurs="0"/>
        <xs:element ref="eu_shipping" minOccurs="0"/>
        <xs:element ref="non_eu_shipping" minOccurs="0"/>
        <xs:element ref="eu_goods" minOccurs="0"/>
        <xs:element ref="quantity" minOccurs="0"/>
        <xs:element ref="destination" minOccurs="0"/>
        <xs:element ref="freight_currency" minOccurs="0"/>
        <xs:element ref="delivery_conditions" minOccurs="0"/>
        <xs:element ref="additional_reference_2" minOccurs="0"/>
        <xs:element ref="additional_status" minOccurs="0"/>
        <xs:element ref="export_origin" minOccurs="0"/>
        <xs:element ref="procedure_code" minOccurs="0"/>
        <xs:element ref="exchange_currency" minOccurs="0"/>
        <xs:element ref="freight_exchange_rate" minOccurs="0"/>
        <xs:element ref="afs_status" minOccurs="0"/>
        <xs:element ref="row_note" minOccurs="0"/>
        <xs:element ref="additional_reference_3" minOccurs="0"/>
        <xs:element ref="additional_codes" minOccurs="0"/>
        <xs:element ref="document_codes" minOccurs="0"/>
        <xs:element ref="previousdocuments" minOccurs="0"/>
        <xs:element ref="container" minOccurs="0"/>
        <xs:element ref="goodsstatuscode" minOccurs="0"/>
        <xs:element ref="additionaldocuments" minOccurs="0"/>
        <xs:element ref="goods_location" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="integration_data" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="tariff_units" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="actors" minOccurs="0"/>
        <xs:element ref="classifications" minOccurs="0"/>
        <xs:element ref="authorisations" minOccurs="0"/>
        <xs:element ref="nature_of_transaction" minOccurs="0"/>
        <xs:element ref="customsvaluation" minOccurs="0"/>
        <xs:element ref="preferential_origin" minOccurs="0"/>
        <xs:element ref="valuationadjustmentcode" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="tradeterms" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
      <xs:attribute name="id" use="required" type="xs:integer"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="description" type="xs:string"/>
  <xs:element name="goods_id_se" type="validategoodsid"/>
  <xs:element name="goods_id_no" type="validategoodsid"/>
  <xs:element name="goods_origin" type="validatecountrycode"/>
  <xs:element name="gross_weight" type="positivedecimalzero"/>
  <xs:element name="benefit" type="xs:string"/>
  <xs:element name="net_weight" type="positivedecimalzero"/>
  <xs:element name="additional_unit_se" type="xs:string"/>
  <xs:element name="additional_unit_no" type="xs:string"/>
  <xs:element name="price_currency" type="validatecurrency"/>
  <xs:element name="price" type="positivedecimalzero"/>
  <xs:element name="freight_cost" type="positivedecimalzero"/>
  <xs:element name="certificate_type" type="xs:string"/>
  <xs:element name="certificate_reference" type="xs:string"/>
  <xs:element name="certificate_date_time" type="xs:dateTime"/>
  <xs:element name="certificate_end_date_time" type="xs:dateTime"/>
  <xs:element name="additional_certificate_type" type="xs:string"/>
  <xs:element name="additional_certificate_reference" type="xs:string"/>
  <xs:element name="additional_certificate_date_time" type="xs:dateTime"/>
  <xs:element name="additional_certificate_end_date_time" type="xs:dateTime"/>
  <xs:element name="certificate_quantity" type="xs:integer"/>
  <xs:element name="textile_licence_number" type="xs:string"/>
  <xs:element name="textile_licence_amount" type="positivedecimalzero"/>
  <xs:element name="invoice_declaration" type="xs:string"/>
  <xs:element name="invocie_declaration" type="xs:string"/>
  <xs:element name="exchange_rate" type="positivedecimalzero"/>
  <xs:element name="vat_code" type="positivedecimalzero"/>
  <xs:element name="taxes">
    <xs:complexType>
      <xs:sequence minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="tax"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="tax">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="tax_code"/>
        <xs:element ref="tax_base"/>
        <xs:element ref="tax_amount"/>
        <xs:element ref="tax_unit"/>
        <xs:element ref="tax_rate" minOccurs="0"/>
        <xs:element ref="tax_sequence" minOccurs="0"/>
        <xs:element ref="measurement_unit" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="tax_code" type="xs:string"/>
  <xs:element name="tax_base" type="positivedecimalzero"/>
  <xs:element name="tax_amount" type="positivedecimalzero"/>
  <xs:element name="tax_unit" type="xs:string"/>
  <xs:element name="tax_rate" type="positivedecimalzero"/>
  <xs:element name="tax_sequence" type="xs:positiveInteger"/>
  <xs:element name="measurement_unit" type="xs:string"/>
  <xs:element name="internal_reference" type="xs:string"/>
  <xs:element name="ucr_reference" type="xs:string"/>
  <xs:element name="alarm">
    <xs:complexType>
      <xs:sequence minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="event"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="event" type="xs:string"/>
  <xs:element name="additional_information">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="type" minOccurs="0"/>
        <xs:element ref="code" minOccurs="0"/>
        <xs:element ref="text" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="type" type="xs:string"/>
  <xs:element name="code" type="xs:string"/>
  <xs:element name="text" type="xs:string"/>
  <xs:element name="additional_reference" type="xs:string"/>
  <xs:element name="eu_shipping" type="positivedecimalzero"/>
  <xs:element name="non_eu_shipping" type="positivedecimalzero"/>
  <xs:element name="eu_goods" type="xs:boolean"/>
  <xs:element name="quantity" type="xs:positiveInteger"/>
  <xs:element name="freight_currency" type="validatecurrency"/>
  <xs:element name="additional_reference_2" type="xs:string"/>
  <xs:element name="additional_status" type="xs:string"/>
  <xs:element name="exchange_currency" type="validatecurrency"/>
  <xs:element name="freight_exchange_rate" type="positivedecimalzero"/>
  <xs:element name="afs_status" type="xs:boolean"/>
  <xs:element name="row_note" type="xs:string"/>
  <xs:element name="additional_reference_3" type="xs:string"/>
  <xs:element name="additional_codes">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="addcode1"/>
        <xs:element ref="addcode2"/>
        <xs:element ref="addcode3"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="addcode1" type="xs:string"/>
  <xs:element name="addcode2" type="xs:string"/>
  <xs:element name="addcode3" type="xs:string"/>
  <xs:element name="document_codes">
    <xs:complexType>
      <xs:sequence minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="doccode" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="doccode" type="xs:string"/>
  <xs:element name="container">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="container_no" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="container_no" type="xs:string"/>
  <xs:element name="procedure_code" type="xs:string"/>
  <xs:element name="goods_location">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="id" type="xs:string" minOccurs="0"/>
        <xs:element name="name" type="xs:string" minOccurs="0"/>
        <xs:element name="type_code" type="xs:string" minOccurs="0"/>
        <xs:element name="address_type_code" type="xs:string" minOccurs="0"/>
        <xs:element ref="economic_operator" minOccurs="0"/>
        <xs:element ref="address" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="economic_operator">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="identification"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="identification" type="xs:string"/>
  <xs:element name="address">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="address_line" type="xs:string" minOccurs="0"/>
        <xs:element name="postal_code" type="xs:string" minOccurs="0"/>
        <xs:element name="type_code" type="xs:string" minOccurs="0"/>
        <xs:element name="city" type="xs:string" minOccurs="0"/>
        <xs:element name="country_code" type="xs:string" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="previousdocuments">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="previous_document" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="previous_document">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="categorycode" type="xs:string" minOccurs="0"/>
        <xs:element name="id" type="xs:string" minOccurs="0"/>
        <xs:element name="typecode" type="xs:string" minOccurs="0"/>
        <xs:element name="linenumeric" type="xs:string" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="additionaldocuments">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="additional_document" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="additional_document">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="id" type="xs:string" minOccurs="0"/>
        <xs:element name="typecode" type="xs:string" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="authorisation_holder">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="id" type="xs:string" minOccurs="0"/>
        <xs:element name="categorycode" type="xs:string" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="test_flag" type="xs:boolean"/>
  <xs:element name="estimated_time_of_arrival" type="xs:dateTime"/>
  <xs:element name="packaging">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="packagemark" minOccurs="0" type="xs:string"/>
        <xs:element name="quantity" minOccurs="0" type="xs:integer"/>
        <xs:element name="packages_type" minOccurs="0" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="integration_data">
    <xs:complexType>
      <xs:sequence minOccurs="1" maxOccurs="unbounded">
        <xs:element ref="data"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="data" type="integration_data_type"/>
  <xs:complexType name="integration_data_type">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="id" type="xs:string"/>
        <xs:attribute name="type" type="xs:string"/>
        <xs:attribute name="description" type="xs:string"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <!-- START Tariff unit -->
  <xs:element name="tariff_units">
    <xs:complexType>
      <xs:sequence minOccurs="1" maxOccurs="unbounded">
        <xs:element ref="tariff_unit"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="tariff_unit" type="tariff_unit_type"/>
  
  <xs:complexType name="tariff_unit_type">
    <xs:simpleContent>
      <xs:extension base="positivedecimalnozero">
        <xs:attribute name="country" type="xs:string"/>
        <xs:attribute name="unit" type="xs:string"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <!-- END Tariff unit -->


  <!-- HEAD TAG - PROCESS -->
  <xs:element name="process" type="xs:boolean"/>
  <!-- END HEAD TAG - PROCESS -->
  
  <!-- START actors -->
  <xs:element name="actors">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="actor"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="actor">
    <xs:complexType>
      <xs:complexContent>
        <xs:extension base="id">
          <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="1" ref="name"/>
            <xs:element ref="contactname" minOccurs="0" maxOccurs="1"/>
            <xs:element ref="contactphone" minOccurs="0" maxOccurs="1"/>
            <xs:element ref="contactemail" minOccurs="0" maxOccurs="1"/>
            <xs:element ref="address" minOccurs="0" maxOccurs="1"/>
          </xs:sequence>
          <xs:attribute name="rolecode" use="required" type="validaterolecode"/>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:element>
  <xs:element name="name" type="xs:string"/>
  <xs:element name="contactname" type="xs:string"/>
  <xs:element name="contactphone" type="xs:string"/>
  <xs:element name="contactemail" type="xs:string"/>
  <xs:complexType name="id">
    <xs:sequence>
      <xs:element ref="id" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>
  <xs:element name="id" type="xs:string" />
    
  <!-- END actors  -->
  <!-- START authorisations -->
  <xs:element name="authorisations">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="99" ref="authorisation"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="authorisation">
    <xs:complexType>
      <xs:complexContent>
        <xs:extension base="id">
          <xs:sequence>
            <xs:element ref="typecode" minOccurs="0" maxOccurs="1"/>
            <xs:element ref="authorisation_holder" minOccurs="0" maxOccurs="1"/>
          </xs:sequence>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:element>
  <xs:element name="typecode" type="xs:string" />
  <!-- END authorisations -->
  
  <!-- START tradeterms -->
  <xs:element name="tradeterms">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="conditioncode" minOccurs="1" maxOccurs="1"/>
        <xs:element ref="locationid" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="locationname" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="countrycode" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="description" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="conditioncode" type="validatetradeterm"/>
  <xs:element name="locationid" type="xs:string"/>
  <xs:element name="locationname" type="xs:string"/>
  <xs:element name="countrycode" type="validatecountrycode"/>
  <!--xs:element name="description" type="xs:string"/> -->
  <!-- END tradeterms-->
  
  <!-- START customsvaluation -->
  <xs:element name="customsvaluation">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" ref="methodcode"/>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="chargededuction"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="methodcode" type="xs:integer"/>
  <xs:element name="chargededuction">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="chargetypecode" minOccurs="0"/>
        <xs:element ref="deductionamount" minOccurs="0"/>
        <xs:element ref="deductioncurrency" minOccurs="0"/>
        <xs:element ref="typecode" minOccurs="0"/>
        <xs:element ref="amount" minOccurs="0"/>
        <xs:element ref="currency" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="chargetypecode" type="xs:NCName"/>
  <xs:element name="deductionamount" type="xs:decimal"/>
  <xs:element name="deductioncurrency" type="validatecurrency"/>
  <xs:element name="amount" type="xs:decimal"/>
  <xs:element name="currency" type="validatecurrency"/>
  <!-- END customsvaluation -->
  

  <!-- START template -->
  <xs:element name="template">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" ref="type"/>
        <xs:element minOccurs="1" maxOccurs="1" ref="reference"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <!-- END customsvaluation -->

  <!-- START classifications -->
  <xs:element name="classifications">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="classification"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="classification">
    <xs:complexType>
      <xs:complexContent>
        <xs:extension base="id">
          <xs:attribute name="type" use="required" type="validateclassification"/>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:element>
  <!-- END classifications -->
  
  <!-- START transport means -->
  <xs:element name="transport_means">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="transport_mean"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="transport_mean">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="type_of_identification"/>
        <xs:element ref="id_number"/>
        <xs:element ref="nationality"/>
      </xs:sequence>
      <xs:attribute name="type" use="required" type="validatetransportmeantype"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="type_of_identification" type="xs:integer"/>
  <xs:element name="id_number" type="xs:string"/>
  <xs:element name="nationality" type="validatecountrycode"/>
  
  <xs:simpleType name="validatetransportmeantype">
    <xs:restriction base="xs:string">
      <xs:enumeration value="DEPARTURE"/>
      <xs:enumeration value="BORDER"/>
    </xs:restriction>
  </xs:simpleType>
  <!-- END transport means -->
  
  
  <xs:element name="preferential_origin" type="validatecountrycode"/>
  <xs:element name="valuationadjustmentcode" type="xs:string"/>

  <!-- START ConsignmentRoutes -->
  <xs:element name="consignmentroute">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="countrycode" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <!-- END ConsignmentRoutes -->
  

  <!-- RULES -->
  <xs:element name="goodsstatuscode" type="xs:string"/>
  <xs:simpleType name="positivedecimalnozero">
    <xs:restriction base="xs:decimal">
      <xs:minExclusive value="0"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="positivedecimalzero">
    <xs:restriction base="xs:decimal">
      <xs:minInclusive value="0"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="validategoodsid">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9]{10}|[0-9]{8}|[0-9]{6}|()"/>
      <!-- Får vara tom, 8 eller 10 -->
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="validatecurrency">
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z]{3}|()"/>
      <!-- A-Z 3tkn -->
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="validatecountrycode">
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z]{2}|()"/>
      <!-- A-Z 2tkn -->
    </xs:restriction>
  </xs:simpleType>
  <!-- actor rolecode -->
  <xs:simpleType name="validaterolecode">
    <xs:restriction base="xs:string">
      <xs:enumeration value="CA"/>
      <xs:enumeration value="CN"/>
      <xs:enumeration value="CS"/>
      <xs:enumeration value="FW"/>
      <xs:enumeration value="MW"/>
      <xs:enumeration value="WH"/>
      <xs:enumeration value="DT"/>
      <xs:enumeration value="ZP"/>
      <xs:enumeration value="ZG"/>
      <xs:enumeration value="EX"/>
      <xs:enumeration value="CZ"/>
      <xs:enumeration value="SE"/>
      <xs:enumeration value="IM"/>
      <xs:enumeration value="BY"/>
      <xs:enumeration value="CA"/>
      <!-- Special for IOSS --> 
      <xs:enumeration value="IOSS-ACTOR"/>
      <xs:enumeration value="IOSS-CONSUMER"/>
      <xs:enumeration value="IOSS-INDIRECT-AGENT"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="validatetradeterm">
    <xs:restriction base="xs:string">
      <xs:enumeration value="EXW"/>
      <xs:enumeration value="FCA"/>
      <xs:enumeration value="CPT"/>
      <xs:enumeration value="CIP"/>
      <xs:enumeration value="DAP"/>
      <xs:enumeration value="DPU"/>
      <xs:enumeration value="DDP"/>
      <xs:enumeration value="FAS"/>
      <xs:enumeration value="FOB"/>
      <xs:enumeration value="CFR"/>
      <xs:enumeration value="CIF"/>
      <xs:enumeration value="XXX"/>
    </xs:restriction>
  </xs:simpleType>
  <!-- classification NAT TAT -->
  <xs:simpleType name="validateclassification">
    <xs:restriction base="xs:string">
      <xs:enumeration value="NAT"/>
      <xs:enumeration value="TAT"/>
      <xs:enumeration value="CUS"/>
    </xs:restriction>
  </xs:simpleType>
  <!-- classification NAT TAT -->
  <xs:simpleType name="validatevaluationadjustmentcode">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-1]{4}|()"/>
      <!-- A-Z 3tkn -->
    </xs:restriction>
  </xs:simpleType>
</xs:schema>
