<?xml version="1.0" encoding="utf-8" ?>
<!--
/*   Copyright 2004 The Apache Software Foundation
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *  limitations under the License.
 */
-->

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <!-- global elems -->
    <xsd:element name="testroot">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="testAtomicTypeElem" type="attachmentTypes"/>
                <xsd:element name="testListTypeElem" type="attchmentExtensionListTypes"/>
                <xsd:element name="testUnionTypeElem" type="union.attachmentUnionType" maxOccurs="unbounded"/>
                <xsd:element ref="header"/> <!-- simple content test -->
                <xsd:element name="testComplexTypeElementOnlyContentElem" type="mailsType"/>
                <xsd:element name="testComplexTypeMixedElem" type="mixedContentType"/>
                <xsd:element name="testComplexTypeEmptyElem" type="emptyContentType"/>
                <xsd:element name="testChoiceGroupElem" type="choiceGroupType"/>
                <xsd:element name="testAllGroupElem" type="allGroupType"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>


    <xsd:element name="testAtomicTypeElem" type="attachmentTypes"/>
    <xsd:element name="testListTypeElem" type="attchmentExtensionListTypes"/>
    <xsd:element name="testUnionTypeElem" type="union.attachmentUnionType"/>
    <xsd:element name="testComplexTypeSimpleContentElem" type="headerType"/> <!-- simple content test -->
    <xsd:element name="testComplexTypeElementOnlyContentElem" type="mailsType"/>
    <xsd:element name="testComplexTypeMixedElem" type="mixedContentType"/>
    <xsd:element name="testComplexTypeEmptyElem" type="emptyContentType"/>
    <xsd:element name="testChoiceGroupElem" type="choiceGroupType"/>
    <xsd:element name="testAllGroupElem" type="allGroupType"/>

    <!--  Types added for testing -->
    <!-- Simple Types:atomic type -->
    <xsd:simpleType name="attachmentTypes">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="MS Word"/>
            <xsd:enumeration value="Adobe Acrobat"/>
            <xsd:enumeration value="Ascii Text"/>
            <xsd:enumeration value="Web Page"/>
        </xsd:restriction>
    </xsd:simpleType>

    <!-- Simple Types:list type -->
    <xsd:simpleType name="attachmentNums">
        <xsd:restriction base="xsd:integer">
            <xsd:minInclusive value="1"/>
            <xsd:maxInclusive value="4"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="attchmentExtensionListTypes">
        <xsd:list itemType="attachmentNums"/>
    </xsd:simpleType>

    <!-- Simple Types:union type -->
    <xsd:simpleType name="union.attachmentUnionType">
        <xsd:union memberTypes="attachmentTypes attchmentExtensionListTypes">
        </xsd:union>
    </xsd:simpleType>

    <!--  End of Simple Types added for testing -->

    <!-- complex types adding testing -->
    <!-- complex type :simple content : refers to element header-->
    <xsd:complexType name="headerType">
        <xsd:simpleContent>
            <xsd:extension base="xsd:string">
                <xsd:attribute ref="name" use="required"/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

    <!-- complex type :element only  content : refers to element header-->

    <xsd:complexType name="mailsType">
        <xsd:sequence minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="mail" type="mailType"/>
        </xsd:sequence>
    </xsd:complexType>

    <!-- complex type :mixed only content -->

    <xsd:complexType name="mixedContentType" mixed="true">
        <xsd:sequence minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="mail" type="mailType"/>
        </xsd:sequence>
    </xsd:complexType>

    <!-- complex type : empty content  -->

    <xsd:complexType name="emptyContentType">
        <xsd:attribute name="value" type="xsd:integer"/>
    </xsd:complexType>

    <!-- complex types - choice model grouping -->
    <xsd:complexType name="choiceGroupType">
        <xsd:choice maxOccurs="unbounded">
            <xsd:element name="Lang" type="xsd:string"/>
            <xsd:element name="Font" type="xsd:string"/>
            <xsd:element name="Fontcolor" type="xsd:string"/>
        </xsd:choice>
    </xsd:complexType>


    <!-- complex types - choice 'all' grouping -->
    <xsd:complexType name="allGroupType">
        <xsd:all>
            <xsd:element name="Greetings" type="xsd:string"/>
            <xsd:element name="Signature" type="xsd:string"/>
            <xsd:element name="ContactNumber" type="xsd:string"/>
        </xsd:all>
    </xsd:complexType>


    <!-- other types , attributes and elems from the email schema -->
    <xsd:element name="mails" type="mailsType"/>
    <xsd:element name="Date" type="xsd:dateTime"/>
    <xsd:element name="header" type="headerType" />

    <xsd:attribute name="name" type="xsd:string"/>

    <xsd:attributeGroup name="mimeTypeAttributes">
        <xsd:attribute name="type" type="mimeTopLevelType" use="required"/>
        <xsd:attribute name="subtype" type="xsd:string" use="required"/>
    </xsd:attributeGroup>

    <xsd:complexType name="mailType">
        <xsd:sequence>
            <xsd:element name="envelope" type="envelopeType"/>
            <xsd:element name="body" type="bodyType"/>
            <xsd:element name="attachment" type="attachmentType"
                minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute use="required" name="id" type="xsd:integer"/>
    </xsd:complexType>

    <xsd:complexType name="envelopeType">
        <xsd:sequence>
            <xsd:element name="From" type="xsd:string"/>
            <xsd:element name="To" type="xsd:string"/>
            <xsd:element ref="Date"/>
            <xsd:element name="Subject" type="xsd:string"/>
            <xsd:element ref="header" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute name="From" type="xsd:string" use="required"/>
    </xsd:complexType>

    <xsd:simpleType name="bodyType">
        <xsd:restriction base="xsd:string"/>
    </xsd:simpleType>

    <xsd:complexType name="attachmentType">
        <xsd:group ref="attachmentContent"/>
        <xsd:attribute ref="name" use="required"/>
    </xsd:complexType>

    <xsd:group name="attachmentContent">
        <xsd:sequence>
            <xsd:element name="mimetype">
                <xsd:complexType>
                    <xsd:attributeGroup ref="mimeTypeAttributes"/>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="content" type="xsd:string" minOccurs="0"/>
        </xsd:sequence>
    </xsd:group>

    <xsd:simpleType name="mimeTopLevelType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="text"/>
            <xsd:enumeration value="multipart"/>
            <xsd:enumeration value="application"/>
            <xsd:enumeration value="message"/>
            <xsd:enumeration value="image"/>
            <xsd:enumeration value="audio"/>
            <xsd:enumeration value="video"/>
        </xsd:restriction>
    </xsd:simpleType>

</xsd:schema>
