<?xml version="1.0" encoding="UTF-8" ?>
<!--
    NamesforLife Taxon Information Object XML Schema

    Copyright (c) 2024, The Regents of the University of California, through
    Lawrence Berkeley National Laboratory (subject to receipt of any required
    approvals from the U.S. Dept. of Energy). All rights reserved.

    CLOCKSS system has permission to ingest, preserve, and serve this Archival Unit.
    LOCKSS system has permission to collect, preserve, and serve this Archival Unit.

    This content is licensed under a Creative Commons Attribution 3.0 International license.
    https://creativecommons.org/licenses/by/3.0/
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://namesforlife.com/ns/taxon" targetNamespace="http://namesforlife.com/ns/taxon" xmlns:exemplar="http://namesforlife.com/ns/exemplar" xmlns:reference="http://namesforlife.com/ns/reference" xmlns:common="http://namesforlife.com/ns/common" elementFormDefault="qualified">

    <xs:import schemaLocation="exemplar.xsd" namespace="http://namesforlife.com/ns/exemplar" />
    <xs:import schemaLocation="reference.xsd" namespace="http://namesforlife.com/ns/reference" />
    <xs:import schemaLocation="common.xsd" namespace="http://namesforlife.com/ns/common" />

    <!-- The document element for a NamesforLife Taxon Information Object. -->
    <xs:element name="taxon" type="taxonType" />

    <!-- Taxon Identifier type -->
    <xs:complexType name="taxonIdentifierType">
        <xs:complexContent>
            <xs:extension base="common:informationObjectType">
                <xs:sequence>
                    <xs:element ref="common:nomenclature" minOccurs="1" maxOccurs="1" />
                </xs:sequence>
                <xs:attribute name="rank" type="common:rankEnumType" use="required" />
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- Taxon Equivalence type -->
    <xs:complexType name="taxonEquivalenceType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="accession" type="xs:string" use="required" /> <!-- e.g., a TaxID or UniProt identifier -->
                <xs:attribute name="rank" type="xs:string" use="required" /> <!-- e.g., the rank of the other taxon may be different -->
                <xs:attribute name="nomos" type="xs:string" use="required" /> <!-- e.g., NCBI or UniProt -->
                <xs:attribute name="relation" type="xs:string" use="required" /> <!-- e.g., broader, narrower, exactMatch, closeMatch -->
                <xs:attribute name="url" type="xs:string" use="optional" /> <!-- TODO: Use xs:url instead of xs:string. -->
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    
    <!-- Top level type for a NamesforLife Taxon Information Object, corresponding to 10.1601/tx.##### -->
    <xs:complexType name="taxonType">
        <xs:complexContent>
            <xs:extension base="taxonIdentifierType">
                <xs:sequence>
                    <xs:element ref="common:nomenclatural-type" minOccurs="0" maxOccurs="1" />
                    <xs:element name="taxonomic-equivalence" minOccurs="0" maxOccurs="1">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="related-taxon" minOccurs="0" maxOccurs="unbounded" type="taxonEquivalenceType" />
                            </xs:sequence>
                        </xs:complexType>
                    </xs:element>
                    <xs:element name="ancestor" minOccurs="0" maxOccurs="1" type="taxonType" />
                    <xs:element name="parent" minOccurs="0" maxOccurs="unbounded" type="taxonType" />
                    <xs:element name="sibling" minOccurs="0" maxOccurs="unbounded" type="taxonType" />
                    <xs:element name="child" minOccurs="0" maxOccurs="unbounded" type="taxonType" />
                    <xs:element ref="exemplar:exemplars" minOccurs="0" maxOccurs="1" />
                    <xs:element ref="reference:bibliography" minOccurs="0" maxOccurs="1" />
                    <xs:element ref="common:annotation" minOccurs="0" maxOccurs="unbounded" />
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

</xs:schema>
