<?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xml="http://www.w3.org/XML/1998/namespace" 
    xmlns:xlink="http://www.w3.org/1999/xlink"
    targetNamespace="http://www.nexml.org/1.0"
    xmlns="http://www.nexml.org/1.0">
    
    <xs:include schemaLocation="meta/annotations.xsd"/>
    <xs:annotation>
        <xs:documentation>
            This module defines abstract superclasses. In xml schema, inheritance of complex types
            is either through extension or through restriction. Extensions in this context means that
            the child class can have more types of elements appended to the end of its children, and/or
            more attributes. Restriction means that the child class is more limited than the base class,
            in that it might have fewer child elements, fewer attributes, or more restricted child 
            element types.<br /><br />
            The nexml schema uses inheritance such that abstract superclasses - i.e. those defined in
            this module - extend each other to form a useful tree of superclasses, from which child
            classes then derive by restriction. This is done so that for any type there is always an
            exhaustive abstract superclass, to which parsers should be adapted, so that derived 
            instances won't have surprising substructures.
        </xs:documentation>
    </xs:annotation>
    
    <!-- a labelled element that encloses a key/value dictionary -->
    <xs:complexType name="Annotated" abstract="true">
        <xs:annotation>
            <xs:documentation>
                The Annotated complexType is a super class for objects that 
                optionally have key/value annotations of type Dict.
            </xs:documentation>
        </xs:annotation>          
        <xs:complexContent>
            <xs:extension base="Base">
                <xs:sequence>
                    <xs:element name="dict" type="Dict" minOccurs="0" maxOccurs="unbounded"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>    

    <!-- an IDTagged element with a human readable label -->
    <xs:complexType name="Labelled" abstract="true">
        <xs:annotation>
            <xs:documentation>
                The Labelled complexType is a super class for objects that 
                optionally have label attributes to use as a (non-unique)
                name of type xs:string.
            </xs:documentation>
        </xs:annotation>        
        <xs:complexContent>
            <xs:extension base="Annotated">
                <xs:attribute name="label" type="xs:string" use="optional"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>    
            
    <!-- any element that requires an ID -->
    <xs:complexType name="IDTagged" abstract="true">
        <xs:annotation>
            <xs:documentation>
                The IDTagged complexType is a super class for objects that require
                unique id attributes of type xs:NCName. IDTagged doesn't define
                scope for uniqueness, derivations are free to do so using xs:keyRef.
            </xs:documentation>
        </xs:annotation>
        <xs:complexContent>
            <xs:extension base="Labelled">
                <xs:sequence/>
                <xs:attribute name="id" type="xs:NCName" use="required"/>
            </xs:extension>
        </xs:complexContent>        
    </xs:complexType>    
    
    <!-- elements that enclose "class" elements -->
    <xs:complexType name="Segmented" abstract="true">
        <xs:annotation>
            <xs:documentation>
                The Segmented complexType is for elements that contain multiple child 
                elements of the same type, e.g. multiple cells in a row, multiple nodes
                in a tree, etc. Segmented elements can hold one or more elements of type
                Class, such that the segments can refer to the ID of the class they belong
                to.
            </xs:documentation>
        </xs:annotation>
        <xs:complexContent>
            <xs:extension base="IDTagged">
                <xs:sequence>
                    <xs:element name="class" type="Class" minOccurs="0" maxOccurs="unbounded"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>    
    
    <!-- an annotated element with a required link to an otu -->
    <xs:complexType name="TaxonLinked" abstract="true">
        <xs:annotation>
            <xs:documentation>
                The TaxonLinked complexType is a super class for objects that 
                require a taxon id reference.
            </xs:documentation>
        </xs:annotation>         
        <xs:complexContent>
            <xs:extension base="IDTagged">
                <xs:attribute name="otu" type="xs:NCName" use="required"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <!-- an annotated element with an optional link to an otu -->
    <xs:complexType name="OptionalTaxonLinked" abstract="true">
        <xs:annotation>
            <xs:documentation>
                The OptionalOTULinked complexType is a super class for objects that 
                that optionally have an otu id reference.
            </xs:documentation>
        </xs:annotation>          
        <xs:complexContent>
            <xs:extension base="IDTagged">
                <xs:attribute name="otu" type="xs:NCName" use="optional"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>    
    
    <!-- an annotated element with a required link to an otu container -->
    <xs:complexType name="TaxaLinked" abstract="true">
        <xs:annotation>
            <xs:documentation>
                The TaxaLinked complexType is a super class for objects that 
                that require an otus id reference.
            </xs:documentation>
        </xs:annotation>         
        <xs:complexContent>
            <xs:extension base="IDTagged">
                <xs:attribute name="otus" type="xs:NCName" use="required"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <!-- class element -->
    <xs:complexType name="Class" abstract="false">
        <xs:annotation>
            <xs:documentation>
                Elements of the Class complexType are elements with an ID to which
                other elements refer using the "class" attribute. The purpose of this 
                to allow creation of sets, but rather than having a set specify its
                members (such as character sets in nexus), in nexml the members specify
                which class(es) they belong to. This is more idiomatic for xml, consider
                for example the "class" attribute in (X)HTML which works the same way,
                and is used for example for cascading style sheets.
            </xs:documentation>
        </xs:annotation>
        <xs:complexContent>
            <xs:extension base="IDTagged"/>            
        </xs:complexContent>
    </xs:complexType>  
           
</xs:schema>