<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.morphbank.net/mbsvc3/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:dwc="http://rs.tdwg.org/dwc/dwcore/" xmlns:dwcg="http://rs.tdwg.org/dwc/geospatial/"
    xmlns:dwcc="http://rs.tdwg.org/dwc/curatorial/" xmlns:dcterms="http://purl.org/dc/terms/"
    targetNamespace="http://www.morphbank.net/mbsvc3/" attributeFormDefault="unqualified">
    <xs:import namespace="http://rs.tdwg.org/dwc/dwcore/"
        schemaLocation="http://rs.tdwg.org/dwc/tdwg_dw_core.xsd"/>
    <xs:import namespace="http://rs.tdwg.org/dwc/geospatial/"
        schemaLocation="http://rs.tdwg.org/dwc/tdwg_dw_geospatial.xsd"/>
    <xs:import namespace="http://rs.tdwg.org/dwc/curatorial/"
        schemaLocation="http://rs.tdwg.org/dwc/tdwg_dw_curatorial.xsd"/>
    <xs:element name="request">
        <xs:annotation>
            <xs:documentation>Request for morphbank information</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element name="submitter" type="credentials" minOccurs="0"/>
                <xs:element name="query" type="query" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element name="insert" type="insert" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element name="update" type="update" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="responses">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="status" type="xs:string" minOccurs="0"/>
                <xs:element name="response" type="response" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="response" type="response"/>

    <xs:complexType name="response">
        <xs:annotation>
            <xs:documentation>Response for request</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:group ref="xmlObjectSet"/>
            <xs:element name="object" type="xmlObject" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="credentials">
        <xs:sequence>
            <xs:element name="keyString" type="xs:string" minOccurs="0"/>
            <xs:element name="userId" type="xs:int" minOccurs="0"/>
            <xs:element name="uin" type="xs:string" minOccurs="0"/>
            <xs:element name="groupId" type="xs:int" minOccurs="0"/>
            <xs:element name="groupName" type="xs:string" minOccurs="0"/>
            <xs:element name="password" type="xs:string" minOccurs="0"/>
            <xs:element name="userName" type="xs:string" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="requestSummary">
        <xs:sequence>
            <xs:element name="requestType" type="xs:string"/>
            <xs:element name="description" type="xs:string" minOccurs="0"/>
            <xs:element name="submitter" type="credentials" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="query">
        <xs:annotation>
            <xs:documentation>Request for Information</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="submitter" type="credentials" minOccurs="0"/>
            <xs:element name="method" type="xs:string">
                <xs:annotation>
                    <xs:documentation>select from querystring, id, taxonname,
                        keyword</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="format" type="xs:string">
                <xs:annotation>
                    <xs:documentation>select from xml, svc, id, rdf, rss</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="keywords" type="xs:string" minOccurs="0"/>
            <xs:element name="limit" type="xs:integer" minOccurs="0"/>
            <xs:element name="firstResult" type="xs:integer" minOccurs="0"/>
            <xs:element name="objectType" type="xs:string" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="queryString" type="xs:string" minOccurs="0"/>
            <xs:element name="taxonName" type="xs:string" minOccurs="0"/>
            <xs:element name="id" type="xs:integer" minOccurs="0"/>
            <xs:element name="changeDate" type="xs:dateTime" minOccurs="0"/>
            <xs:element name="lastChangeDate" type="xs:dateTime" minOccurs="0"/>
            <xs:element name="numChangeDays" type="xs:integer" minOccurs="0"/>
            <xs:element name="geolocated" type="xs:boolean" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="insert">
        <xs:annotation>
            <xs:documentation>Request to insert objects into morphbank </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:group ref="xmlObjectSet"/>
            <xs:element name="object" type="xmlObject" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="update">
        <xs:annotation>
            <xs:documentation>Request to update objects</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:group ref="xmlObjectSet"/>
            <xs:element name="object" type="xmlObject" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:group name="xmlObjectSet">
        <xs:sequence>
            <xs:element name="submitter" type="credentials" minOccurs="0"/>
            <xs:element name="requestSummary" type="requestSummary" minOccurs="0"/>
            <xs:element name="status" type="xs:string" minOccurs="0"/>
            <xs:element name="numberAffected" type="xs:long" minOccurs="0"/>
            <xs:element name="numMatches" type="xs:integer" minOccurs="0"/>
            <xs:element name="numReturned" type="xs:integer" minOccurs="0"/>
            <xs:element name="firstReturned" type="xs:integer" minOccurs="0"/>
        </xs:sequence>
    </xs:group>

    <xs:complexType name="xmlObject">
        <xs:sequence>
            <!-- BaseObject -->
            <xs:element name="sourceId" type="xmlId"/>
            <xs:element name="status" type="xs:string" minOccurs="0"/>
            <xs:element name="type" type="xs:string" maxOccurs="1" minOccurs="0"/>
            <xs:element name="owner" type="credentials" minOccurs="0"/>
            <xs:element name="dateCreated" type="xs:dateTime" minOccurs="0"/>
            <xs:element name="dateLastModified" type="xs:dateTime" minOccurs="0"/>
            <xs:element name="dateToPublish" type="xs:dateTime" minOccurs="0"/>
            <xs:element name="objectTypeId" type="xs:string" minOccurs="0"/>
            <xs:element name="name" type="xs:string" minOccurs="0"/>
            <xs:element name="description" type="xs:string" minOccurs="0"/>
            <xs:element name="submittedBy" type="credentials" minOccurs="0"/>
            <xs:element name="objectLogo" type="xs:string" minOccurs="0"/>
            <xs:element name="thumbUrl" type="xs:string" minOccurs="0"/>
            <xs:element name="detailPageUrl" type="xs:string" minOccurs="0"/>
            <xs:element name="hostServer" type="xs:string" minOccurs="0"/>
            <xs:element name="relatedObject" type="xmlId" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="externalRef" type="extref" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="userProperty" type="userprop" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="geolocated" type="xs:boolean" minOccurs="0"/>
            <xs:element name="determination" type="xmlId" minOccurs="0"/>
            
            <!-- Annotation -->
            <xs:element name="typeAnnotation" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="xLocation" type="xs:long" minOccurs="0"/>
            <xs:element name="yLocation" type="xs:long" minOccurs="0"/>
            <xs:element name="areaHeight" type="xs:long" minOccurs="0"/>
            <xs:element name="areaWidth" type="xs:long" minOccurs="0"/>
            <xs:element name="areaRadius" type="xs:long" minOccurs="0"/>
            <xs:element name="annotationQuality" type="xs:string" minOccurs="0"/>
            <xs:element name="title" type="xs:string" minOccurs="0"/>
            <xs:element name="comment" type="xs:string" minOccurs="0"/>
            <xs:element name="XMLData" type="xs:string" minOccurs="0"/>
            <xs:element name="annotationLabel" type="xs:string" minOccurs="0"/>

            <!-- Determination Annotation -->
            <xs:element name="taxon" type="xmlId" minOccurs="0"/>
            <xs:element name="typeDetAnnotation" type="xs:string" minOccurs="0"/>
            <xs:element name= "sourceOfId" type="xs:string" minOccurs="0"/>
            <xs:element name= "materialsUsedInId" type="xs:string" minOccurs="0"/>
            <xs:element name= "resourcesused" type="xs:string" minOccurs="0"/>
            <xs:element name= "collection" type="xs:string" minOccurs="0"/>
            <xs:element name= "altTaxonName" type="xs:string" minOccurs="0"/>
            
            <!-- Group (see below) -->
            <!-- Image -->
            <xs:element name="image" type="xmlId" minOccurs="0"/>
            <xs:element name="height" type="xs:long" minOccurs="0"/>
            <xs:element name="width" type="xs:long" minOccurs="0"/>
            <xs:element name="resolution" type="xs:string" minOccurs="0"/>
            <xs:element name="magnification" type="xs:double" minOccurs="0"/>
            <xs:element name="imageType" type="xs:string" minOccurs="0"/>
            <xs:element name="copyrightText" type="xs:string" minOccurs="0"/>
            <xs:element name="originalFileName" type="xs:string" minOccurs="0"/>
            <xs:element name="creativeCommons" type="xs:string" minOccurs="0"/>
            <xs:element name="photographer" type="xs:string" minOccurs="0"/>
            <xs:element name="specimen" type="xmlId" minOccurs="0"/>
            <xs:element name="eol" type="xs:string" minOccurs="0"/>
	    <!-- Locality -->
            <!-- Publication -->
            <xs:element name="publicationType" minOccurs="0"/>
            <!-- <xs:element name="address" minOccurs="0"/> -->
            <xs:element name="annote" minOccurs="0"/>
            <xs:element name="author" minOccurs="0"/>
            <xs:element name="publicationTitle" minOccurs="0"/>
            <xs:element name="chapter" minOccurs="0"/>
            <xs:element name="edition" minOccurs="0"/>
            <xs:element name="editor" minOccurs="0"/>
            <xs:element name="howPublished" minOccurs="0"/>
            <xs:element name="institution" minOccurs="0"/>
            <xs:element name="key" minOccurs="0"/>
            <xs:element name="month" minOccurs="0"/>
            <xs:element name="day" minOccurs="0"/>
            <xs:element name="note" minOccurs="0"/>
            <xs:element name="number" minOccurs="0"/>
            <xs:element name="organization" minOccurs="0"/>
            <xs:element name="pages" minOccurs="0"/>
            <xs:element name="publisher" minOccurs="0"/>
            <xs:element name="school" minOccurs="0"/>
            <xs:element name="series" minOccurs="0"/>
            <!-- <xs:element name="title" minOccurs="0"/> -->
            <xs:element name="volume" minOccurs="0"/>
            <xs:element name="year" minOccurs="0"/>
            <xs:element name="isbn" minOccurs="0"/>
            <xs:element name="issn" minOccurs="0"/>

            <!-- Specimen -->
            <xs:element name="standardImage" type="xmlId" minOccurs="0"/>
            <xs:element name="imagesCount " type="xs:int" minOccurs="0"/>
            <xs:element name="locality" type="xmlId" minOccurs="0"/>
            <xs:element name="form" type="xs:string" minOccurs="0"/>
            
            <!-- Taxon -->
            <xs:element name="namespace" type="xs:string" minOccurs="0"/>
            <xs:element name="taxonStatus" type="xs:string" minOccurs="0"/>
            <xs:element name="taxonRank" type="xs:string" minOccurs="0"/>
            <!-- View -->
            <xs:element name="view" type="xmlId" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="viewAngle" type="xs:string" minOccurs="0"/>
            <xs:element name="imagingTechnique" type="xs:string" minOccurs="0"/>
            <xs:element name="imagingPreparationTechnique" type="xs:string" minOccurs="0"/>
            <xs:element name="specimenPart" type="xs:string" minOccurs="0"/>
            <xs:element name="developmentalStage" type="xs:string" minOccurs="0"/>
            <xs:element name="sex" type="xs:string" minOccurs="0"/>
            <xs:element name="viewTSN" type="xs:int" minOccurs="0"/>
            <xs:element name="viewRestrictedTo" type="xmlId" minOccurs="0"/>
            <!-- User -->
            <xs:element name="uin" type="xs:string" minOccurs="0"/>
            <xs:element name="pin" type="xs:string" minOccurs="0"/>
            <xs:element name="userName" type="xs:string" minOccurs="0"/>
            <xs:element name="email" type="xs:string" minOccurs="0"/>
            <xs:element name="affiliation" type="xs:string" minOccurs="0"/>
            <xs:element name="address" type="xs:string" minOccurs="0"/>
            <xs:element name="lastName" type="xs:string" minOccurs="0"/>
            <xs:element name="firstName" type="xs:string" minOccurs="0"/>
            <xs:element name="suffix" type="xs:string" minOccurs="0"/>
            <xs:element name="middleInit" type="xs:string" minOccurs="0"/>
            <xs:element name="street1" type="xs:string" minOccurs="0"/>
            <xs:element name="street2" type="xs:string" minOccurs="0"/>
            <xs:element name="state" type="xs:string" minOccurs="0"/>
            <xs:element name="zipcode" type="xs:string" minOccurs="0"/>
            <xs:element name="userStatus" type="xs:string" minOccurs="0"/>
            <xs:element name="privilegeTSN" type="xs:string" minOccurs="0"/>
            <xs:element name="preferredServer" type="xs:string" minOccurs="0"/>
            <xs:element name="preferredGroup" type="xs:string" minOccurs="0"/>
            <xs:element name="userLogo" type="xs:string" minOccurs="0"/>
            <xs:element name="logoUrl" type="xs:string" minOccurs="0"/>
            <!-- Group -->
            <xs:element name="groupName" type="xs:string" minOccurs="0"/>

            <!-- Darwin Core -->
            <xs:any
                namespace="http://rs.tdwg.org/dwc/dwcore/ http://rs.tdwg.org/dwc/geospatial/ http://rs.tdwg.org/dwc/curatorial/"
                maxOccurs="unbounded" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>Place Darwin Core 2 elements here</xs:documentation>
                </xs:annotation>
            </xs:any>
        </xs:sequence>
        <xs:attribute name="type"/>
    </xs:complexType>

    <xs:complexType name="userprop">
	<xs:attribute name="namespaceURI" type="xs:string"/>
        <xs:attribute name="property" type="xs:string"/>
        <xs:attribute name="value" type="xs:string"/>
    </xs:complexType>
    <xs:complexType name="extref">
        <xs:sequence>
            <xs:element name="label" type="xs:string" minOccurs="0"/>
            <xs:element name="urlData" type="xs:string" minOccurs="0"/>
            <xs:element name="description" type="xs:string" minOccurs="0"/>
            <xs:element name="externalId" type="xs:string" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute name="type" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="xmlId">
        <xs:annotation>
            <xs:documentation>Type id is used for identification of an object and can be a morphbank
                id, lsid, local XML document identifier or external GUID</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="identifier" type="xs:string" minOccurs="0"/>
            <xs:element name="morphbank" type="xs:long" minOccurs="0"/>
            <xs:element name="URI" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="local" type="xs:string" minOccurs="0"/>
            <xs:element name="external" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="index" type="xs:integer"/>
        <xs:attribute name="title" type="xs:string"/>
        <xs:attribute name="role" type="xs:string"/>
        <xs:attribute name="objectType" type="xs:string"/>
        <xs:attribute name="source" type="xs:boolean" default="true"/>
    </xs:complexType>
</xs:schema>
