<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified"
  xmlns="http://namespace.openaire.eu/oaf" targetNamespace="http://namespace.openaire.eu/oaf">

  <xs:annotation>
    <xs:documentation>This schema defines common types that can be re-used.</xs:documentation>
  </xs:annotation>

  <xs:complexType mixed="true" name="classedSchemedElement">
    <xs:attributeGroup ref="classSchemeAttrGroup"/>
  </xs:complexType>

  <xs:attributeGroup name="classSchemeAttrGroup">
    <xs:attribute name="classid" use="required" type="xs:string">
      <xs:annotation>
        <xs:documentation>Identifier of the value in classname with respect to the controlled
          vocabulary with id = schemeid.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="classname" use="required" type="xs:string">
      <xs:annotation>
        <xs:documentation>A value from the controlled vocabulary identified by
          schemeid.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="schemeid" use="required" type="xs:string">
      <xs:annotation>
        <xs:documentation>Identifier of the controlled vocabulary with name
          schemename.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="schemename" use="required" type="xs:string">
      <xs:annotation>
        <xs:documentation>Name of the controlled vocabulary.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:attributeGroup>

  <xs:complexType mixed="true" name="optionalClassedSchemedElement">
    <xs:attributeGroup ref="optionalClassSchemeAttrGroup"/>
  </xs:complexType>

  <xs:attributeGroup name="optionalClassSchemeAttrGroup">
    <xs:attribute name="classid" use="optional" type="xs:string">
      <xs:annotation>
        <xs:documentation>Identifier of the value in classname with respect to the controlled
          vocabulary with id = schemeid.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="classname" use="optional" type="xs:string">
      <xs:annotation>
        <xs:documentation>A value from the controlled vocabulary identified by
          schemeid.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="schemeid" use="optional" type="xs:string">
      <xs:annotation>
        <xs:documentation>Identifier of the controlled vocabulary with name
          schemename.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="schemename" use="optional" type="xs:string">
      <xs:annotation>
        <xs:documentation>Name of the controlled vocabulary.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:attributeGroup>

  <xs:complexType name="namedIdElement">
    <xs:attribute name="id" use="required"/>
    <xs:attribute name="name" use="required"/>
  </xs:complexType>

  <xs:complexType name="labeledIdElement">
    <xs:attribute name="id" use="required"/>
    <xs:attribute name="label" use="required"/>
  </xs:complexType>

  <xs:complexType name="datainfoType">
    <xs:annotation>
      <xs:documentation>Information about the provenance of this record.</xs:documentation>
    </xs:annotation>
    <xs:choice maxOccurs="unbounded">
      <xs:element name="inferred" type="xs:boolean">
        <xs:annotation>
          <xs:documentation>True if this information has been inferred by the automatic inference
            algorithms run by OpenAIRE.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="deletedbyinference" type="xs:boolean">
        <xs:annotation>
          <xs:documentation>True if this information has been deleted by the automatic inference
            algorithms run by OpenAIRE.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="trust" type="xs:string">
        <xs:annotation>
          <xs:documentation>Value of trust of this information. Typically a value in the range
            [0,1]. More the value, more trustwirthy is the infromation.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="inferenceprovenance" type="xs:string"/>
      <xs:element name="provenanceaction" type="classedSchemedElement"/>
    </xs:choice>
  </xs:complexType>

  <xs:complexType name="relsType">
    <xs:annotation>
      <xs:documentation>Relationships to other entities.</xs:documentation>
    </xs:annotation>
    <xs:sequence maxOccurs="unbounded" minOccurs="0">
      <xs:element name="rel" type="relType" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="relType">
    <xs:annotation>
      <xs:documentation>A relationship to another entity</xs:documentation>
    </xs:annotation>
    <xs:choice maxOccurs="unbounded">
      <xs:element name="to" type="relToType"/>
      <xs:element name="ranking" type="xs:integer" minOccurs="0"/>
      <xs:element name="fullname" type="xs:string" minOccurs="0"/>
      <xs:element name="title" type="optionalClassedSchemedElement" minOccurs="0"/>
      <xs:element name="dateofacceptance" type="xs:string" minOccurs="0"/>
      <xs:element name="publisher" type="xs:string" minOccurs="0"/>
      <xs:element name="resulttype" type="classedSchemedElement" minOccurs="0">
        <xs:annotation>
          <xs:documentation>Type of the related result. Valid only if the related entity is a
            result. Allowed values: dataset, publication.</xs:documentation>
        </xs:annotation>
      </xs:element>

      <!-- elements for organisations, some are also valid for datsources and projects -->
      <xs:element name="officialname" type="xs:string" minOccurs="0"/>
      <xs:element name="participantnumber" type="xs:string" minOccurs="0"/>
      <xs:element name="websiteurl" type="xs:string" minOccurs="0"/>
      <xs:element name="code" type="xs:string" minOccurs="0"/>
      <xs:element name="acronym" type="xs:string" minOccurs="0"/>
      <xs:element name="contracttype" type="optionalClassedSchemedElement" minOccurs="0">
        <xs:annotation>
          <xs:documentation>Type of the contract. Allowed values: Article 171 of the Treaty,
            CIP-Eco-Innovation - CIP-Thematic Network, Collaborative project, Combination of CP
            &amp; CSA, Coordination and support action, Network of Excellence, Research for the
            benefit of specific groups, Support for frontier research (ERC), Support for training
            and career development of researchers (Marie Curie) </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="funding" type="fundingFlatType" minOccurs="0"/>
      <!-- elements for datasources -->
      <xs:element name="legalname" type="xs:string" minOccurs="0"/>
      <xs:element name="datasourcetype" type="optionalClassedSchemedElement" minOccurs="0">
        <xs:annotation>
          <xs:documentation>Type of datasource. Allowed values are: aggregator::datarepository,
            aggregator::pubsrepository::institutional, aggregator::pubsrepository::journals,
            aggregator::pubsrepository::unknown, crissystem, datarepository::unknown,
            entityregistry, infospace, pubsrepository::institutional, pubsrepository::journal,
            pubsrepository::mock, pubsrepository::thematic, pubsrepository::unknown, scholarly
            commnication infrastructure, websource </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="datasourcetypeui" type="optionalClassedSchemedElement" minOccurs="0"/>
      <xs:element name="legalshortname" type="xs:string" minOccurs="0"/>
      <xs:element name="country" type="optionalClassedSchemedElement" minOccurs="0">
        <xs:annotation>
          <xs:documentation> The classid attribute contains the ISO 3166-1 alpha-2 code of the
            country. The classname attribute contains the english name of the country.
          </xs:documentation>
        </xs:annotation>
      </xs:element>
      <!-- elements for projects -->
      <xs:element name="fax" type="xs:string" minOccurs="0"/>
      <xs:element name="email" type="xs:string" minOccurs="0"/>
      <xs:element name="phone" type="xs:string" minOccurs="0"/>
    </xs:choice>
    <xs:attribute name="inferenceprovenance"/>
    <xs:attribute name="inferred" use="required" type="xs:boolean"/>
    <xs:attribute name="provenanceaction" type="xs:string"/>
    <xs:attribute name="trust" type="xs:string">
      <xs:annotation>
        <xs:documentation>Value of trust of this information. Typically a value in the range [0,1].
          More the value, more trustwirthy is the infromation.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="relToType">
    <xs:annotation>
      <xs:documentation>Type of the related entity.</xs:documentation>
    </xs:annotation>
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="class" use="required" type="xs:string"><xs:annotation>
          <xs:documentation>The semantics of the relationship between this entity and the entity whose id is in the value of this element.</xs:documentation>
        </xs:annotation></xs:attribute>
        <xs:attribute name="scheme" use="required" type="xs:string"/>
        <xs:attribute name="type" use="required" type="xs:string">
          <xs:annotation>
            <xs:documentation>The type of the related entity: project, organisation, datasource,
              result, person.</xs:documentation>
          </xs:annotation>
        </xs:attribute>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:complexType name="fundingFlatType">
    <xs:sequence>
      <xs:element name="funding_level_0" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="funding_level_1" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="funding_level_2" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="externalreferenceType">
    <xs:sequence>
      <xs:element name="sitename" type="xs:string"/>
      <xs:element name="label" type="xs:string"/>
      <xs:element name="qualifier" type="optionalClassedSchemedElement"/>
      <xs:element name="refidentifier" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>

</xs:schema>
