<?xml version=“1.0” encoding=“UTF-8”?> <xs:schema xmlns=“www.nexml.org/2009” xmlns:xs=“www.w3.org/2001/XMLSchema

targetNamespace="http://www.nexml.org/2009" elementFormDefault="qualified">
<xs:annotation>
  <xs:documentation>
    This module constitutes in effect the 'main' class of the nexml schema.
    It defines the complex type for the root &lt;<a href="#Nexml">nex:nexml</a>&gt; 
    element and a simple type for the schema <a href="#Nexml1_0">"version" attribute</a> 
    of the root element. In addition, this module includes the main schema modules for 
    <a href="../taxa/taxa">OTUs</a>, <a href="../characters/characters">characters</a>, 
    <a href="../trees/trees">trees</a> and <a href="../meta/meta">metadata</a>. The data 
    type definitions in these included schema modules are then used to define element 
    instances in the child substructures of the &lt;nex:nexml&gt; root element.

    $Id: $
  </xs:documentation>
</xs:annotation>

<xs:include schemaLocation="taxa/taxa.xsd"/>
<xs:include schemaLocation="characters/characters.xsd"/>
<xs:include schemaLocation="trees/trees.xsd"/>
<xs:include schemaLocation="meta/annotations.xsd"/>
<!-- xs:include schemaLocation="meta/meta.xsd"/-->
<!--<xs:include schemaLocation="models/models.xsd"/>-->

<xs:simpleType name="Nexml1_0">
  <xs:annotation>
    <xs:documentation>
      This simple type is the fixed version value, which in this
      iteration must be constrained to 0.9 (and will be incremented
      in future versions).
    </xs:documentation>
  </xs:annotation>
  <xs:restriction base="xs:decimal">
    <xs:pattern value="0\.9"/>
  </xs:restriction>
</xs:simpleType>

<xs:complexType name="Nexml" mixed="true">
  <xs:annotation>
    <xs:documentation>
      The root element for nexml.
    </xs:documentation>
  </xs:annotation>
  <xs:complexContent mixed="true">
    <xs:extension base="Annotated">
      <xs:sequence maxOccurs="unbounded" minOccurs="0">
        <xs:element maxOccurs="unbounded" minOccurs="1" name="otus" type="Taxa"/>
        <xs:sequence maxOccurs="unbounded" minOccurs="0">
          <xs:choice>
            <xs:element maxOccurs="unbounded" minOccurs="0" name="characters" type="AbstractBlock"/>
            <xs:element maxOccurs="unbounded" minOccurs="0" name="trees" type="Trees">
              <xs:key name="tree">
                <xs:selector xpath="./tree"/>
                <xs:field xpath="@id"/>
              </xs:key>
            </xs:element>
          </xs:choice>
        </xs:sequence>
      </xs:sequence>
      <xs:attribute name="version" type="Nexml1_0" use="required"/>
      <xs:attribute name="generator" type="xs:string" use="optional"/>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

<!-- the root of the document -->
<xs:element name="nexml" type="Nexml">

  <!-- keys for child-of-root biodata containers: taxa, characters trees -->
  <xs:key name="taxa">
    <xs:selector xpath="./taxa"/>
    <xs:field xpath="@id"/>
  </xs:key>
  <xs:key name="characters">
    <xs:selector xpath="./characters"/>
    <xs:field xpath="@id"/>
  </xs:key>
  <xs:key name="trees">
    <xs:selector xpath="./trees"/>
    <xs:field xpath="@id"/>
  </xs:key>

  <xs:key name="taxon">
    <xs:selector xpath="./taxa/taxon"/>
    <xs:field xpath="@id"/>
  </xs:key>

  <!-- links to taxon objects: from row to taxon, from node to taxon -->
  <xs:keyref name="rowTaxonRef" refer="taxon">
    <xs:selector xpath="./characters/matrix/row"/>
    <xs:field xpath="@taxon"/>
  </xs:keyref>
  <xs:keyref name="listNodeTaxonRef" refer="taxon">
    <xs:selector xpath="./trees/tree/terminal"/>
    <xs:field xpath="@taxon"/>
  </xs:keyref>
  <xs:keyref name="nestedNodeTaxonRef" refer="taxon">
    <xs:selector xpath="./trees/tree/root/internal/*/terminal"/>
    <xs:field xpath="@taxon"/>
  </xs:keyref>

</xs:element>

</xs:schema>