<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.culture.gouv.fr/ns/sdx/sdx" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sdx="http://www.culture.gouv.fr/ns/sdx/sdx" elementFormDefault="qualified">
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>
    <xsd:annotation>
        <xsd:documentation xml:lang="fr">
            Liste des éléments générés par SDX.
            </xsd:documentation>
    </xsd:annotation>
    <xsd:element name="document">
        <xsd:complexType mixed="true">
            <xsd:choice minOccurs="0" maxOccurs="unbounded">
                <xsd:group ref="sdx:blocks"/>
            </xsd:choice>
            <xsd:attribute ref="xml:lang" use="required"/>
            <xsd:attribute name="server" type="xsd:anyURI" use="required"/>
            <xsd:attribute name="api-url" type="xsd:anyURI" use="required"/>
            <xsd:attribute name="app" type="xsd:string" use="required"/>
            <xsd:attribute name="uri" type="xsd:anyURI" use="required"/>
            <xsd:attribute name="query" type="xsd:string" use="required"/>
            <xsd:attribute name="date" type="xsd:string" use="required"/>
        </xsd:complexType>
    </xsd:element>
    <!-- all blocks -->
    <xsd:group name="blocks">
        <xsd:choice>
            <xsd:element ref="sdx:results"/>
            <xsd:element ref="sdx:terms"/>
            <xsd:element ref="sdx:navigation"/>
            <xsd:element ref="sdx:exception"/>
            <xsd:element ref="sdx:user"/>
            <xsd:element ref="sdx:parameters"/>
        </xsd:choice>
    </xsd:group>
    <!-- terms and results shared attributes -->
    <xsd:attributeGroup name="qid">
        <xsd:attribute name="qid" type="xsd:Name" use="required"/>
        <xsd:attribute name="page" type="xsd:byte" use="required"/>
        <xsd:attribute name="pages" type="xsd:byte" use="required"/>
        <xsd:attribute name="hpp" type="xsd:byte" use="required"/>
        <xsd:attribute name="nb" type="xsd:byte" use="required"/>
        <xsd:attribute name="start" type="xsd:byte" use="required"/>
        <xsd:attribute name="end" type="xsd:byte" use="required"/>
    </xsd:attributeGroup>
    <!-- <sdx:results/> -->
    <xsd:element name="results">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="sdx:query"/>
                <xsd:element ref="sdx:sort"/>
                <xsd:element ref="sdx:result" minOccurs="0" maxOccurs="unbounded"/>
            </xsd:sequence>
            <xsd:attributeGroup ref="sdx:qid"/>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:query/> -->
    <xsd:element name="query">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="sdx:query" minOccurs="0" maxOccurs="unbounded"/>
            </xsd:sequence>
            <xsd:attribute name="type" use="required">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:NMTOKEN">
                        <xsd:enumeration value="complex"/>
                        <xsd:enumeration value="field"/>
                        <xsd:enumeration value="simple"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:attribute>
            <xsd:attribute name="luceneQuery" type="xsd:string" use="required"/>
            <xsd:attribute name="operator">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:NMTOKEN">
                        <xsd:enumeration value="and"/>
                        <xsd:enumeration value="or"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:attribute>
            <xsd:attribute name="text" type="xsd:string"/>
            <xsd:attribute name="field" type="xsd:string"/>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:sort/> -->
    <xsd:element name="sort">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="sdx:field"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:result/> -->
    <xsd:element name="result">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="sdx:field" minOccurs="0" maxOccurs="unbounded"/>
            </xsd:sequence>
            <xsd:attribute name="no" use="required" type="xsd:positiveInteger"/>
            <xsd:attribute name="score" use="required" type="xsd:float"/>
            <xsd:attribute name="pctScore" use="required" type="xsd:nonNegativeInteger"/>
            <!--
            <xsd:attribute name="nextDocument"/>
            <xsd:attribute name="previousDocument" type="xsd:string"/>
            -->
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:field/> -->
    <xsd:element name="field">
        <xsd:complexType>
            <xsd:simpleContent>
                <xsd:extension base="xsd:string">
                    <xsd:attribute name="name" use="required">
                        <xsd:simpleType>
                            <xsd:union>
                                <xsd:simpleType>
                                    <xsd:restriction base="xsd:Name">
                                        <xsd:enumeration value="sdxall"/>
                                        <xsd:enumeration value="sdxappid"/>
                                        <xsd:enumeration value="sdxdbid"/>
                                        <xsd:enumeration value="sdxdocid"/>
                                        <xsd:enumeration value="sdxdoctype"/>
                                    </xsd:restriction>
                                </xsd:simpleType>
                                <xsd:simpleType>
                                    <xsd:restriction base="xsd:Name"/>
                                </xsd:simpleType>
                            </xsd:union>
                        </xsd:simpleType>
                    </xsd:attribute>
                    <xsd:attribute name="value"/>
                    <xsd:attribute name="escapedValue"/>
                    <xsd:attribute name="type">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:Name">
                                <xsd:enumeration value="word"/>
                                <xsd:enumeration value="field"/>
                                <xsd:enumeration value="date"/>
                                <xsd:enumeration value="unindexed"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:attribute>
                    <xsd:attribute name="indexed" type="xsd:boolean"/>
                    <xsd:attribute name="tokenized" type="xsd:boolean"/>
                    <xsd:attribute name="order">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:Name">
                                <xsd:enumeration value="ascending"/>
                                <xsd:enumeration value="descending"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:attribute>
                </xsd:extension>
            </xsd:simpleContent>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:terms/> -->
    <xsd:element name="terms">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="sdx:term" minOccurs="0" maxOccurs="unbounded"/>
            </xsd:sequence>
            <xsd:attributeGroup ref="sdx:qid"/>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:term/> -->
    <xsd:element name="term">
        <xsd:complexType>
            <xsd:attribute name="no" use="required" type="xsd:positiveInteger"/>
            <xsd:attribute name="value" use="required"/>
            <xsd:attribute name="escapedValue" use="required"/>
            <xsd:attribute name="field" type="xsd:string" use="required"/>
            <xsd:attribute name="docs" use="required" type="xsd:positiveInteger"/>
            <xsd:attribute name="id" type="xsd:string"/>
            <xsd:attribute name="base" type="xsd:string"/>
            <xsd:attribute name="app" type="xsd:string"/>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:navigation/> -->
    <xsd:element name="navigation">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="sdx:previous"/>
                <xsd:element ref="sdx:next"/>
            </xsd:sequence>
            <xsd:attribute name="docNo" type="xsd:byte" use="required"/>
            <xsd:attribute name="page" type="xsd:boolean" use="required"/>
            <xsd:attribute name="queryId" type="xsd:string" use="required"/>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:next/> -->
    <xsd:element name="next">
        <xsd:complexType>
            <xsd:attribute name="docId" type="xsd:string" use="required"/>
            <xsd:attribute name="app" type="xsd:string" use="required"/>
            <xsd:attribute name="base" type="xsd:string" use="required"/>
            <xsd:attribute name="no" type="xsd:byte" use="required"/>
            <xsd:attribute name="page" type="xsd:byte" use="required"/>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:previous/> -->
    <xsd:element name="previous">
        <xsd:complexType>
            <xsd:attribute name="docId" type="xsd:string" use="required"/>
            <xsd:attribute name="app" type="xsd:string" use="required"/>
            <xsd:attribute name="base" type="xsd:string" use="required"/>
            <xsd:attribute name="no" type="xsd:boolean" use="required"/>
            <xsd:attribute name="page" type="xsd:boolean" use="required"/>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:user/> -->
    <xsd:element name="user">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="sdx:group" minOccurs="0" maxOccurs="unbounded"/>
            </xsd:sequence>
            <xsd:attribute name="id" type="xsd:string"/>
            <xsd:attribute name="firstname" type="xsd:string"/>
            <xsd:attribute name="lastname" type="xsd:string"/>
            <xsd:attribute name="email" type="xsd:string"/>
            <xsd:attribute name="app" type="xsd:string"/>
            <xsd:attribute name="admin" type="xsd:boolean"/>
            <xsd:attribute name="anonymous" type="xsd:boolean"/>
            <xsd:attribute ref="xml:lang"/>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:group/> -->
    <xsd:element name="group">
        <xsd:complexType>
            <xsd:attribute name="id" type="xsd:string" use="required"/>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:parameters/> -->
    <xsd:element name="parameters">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="sdx:parameter" minOccurs="1" maxOccurs="unbounded"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:parameter/> -->
    <xsd:element name="parameter">
        <xsd:complexType>
            <xsd:attribute name="type" use="required">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:NMTOKEN">
                        <xsd:enumeration value="get"/>
                        <xsd:enumeration value="post"/>
                        <xsd:enumeration value="put"/>
                        <xsd:enumeration value="header"/>
                        <xsd:enumeration value="session"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:attribute>
            <xsd:attribute name="name" use="required"/>
            <xsd:attribute name="value" type="xsd:string" use="required"/>
            <xsd:attribute name="escapedValue" type="xsd:string"/>
            <xsd:attribute name="class"/>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:exception/> -->
    <xsd:element name="exception">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="sdx:message"/>
            </xsd:sequence>
            <xsd:attribute ref="xml:lang" use="required"/>
            <xsd:attribute name="code" use="required"/>
        </xsd:complexType>
    </xsd:element>
    <!-- <sdx:message/> -->
    <xsd:element name="message" type="xsd:string"/>
</xsd:schema>
