<?xml version="1.0" encoding="utf-8"?>
<!--
   Moxie Message Schema: moxie_msg.xsd v 0.1 2005/06/15
   
   The Contents of this file are made available subject to the terms of
   the following license

          - GNU Lesser General Public License Version 2 or later

   Peter Lacey, June, 2005

   GNU Lesser General Public License Version 2.1
   =============================================
   Copyright (C) 2005 by Peter Lacey
   Newburyport, MA  01950, USA

   This document is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

   All Rights Reserved.

-->

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://wanderingbarque.com/moxie/2005/06/messaging.xsd"
            targetNamespace="http://wanderingbarque.com/moxie/2005/06/messaging.xsd"
            xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
            xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
            attributeFormDefault="unqualified"
            elementFormDefault="qualified" >

  <xsd:import namespace="http://www.w3.org/2000/09/xmldsig#" 
              schemaLocation="http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd" />
  <xsd:import namespace="http://www.w3.org/2001/04/xmlenc#" 
              schemaLocation="http://www.w3.org/TR/xmlenc-core/xenc-schema.xsd" />

  <xsd:element name="Envelope" >
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Action"   type="ActionType" />
        <xsd:element name="Security" type="SecurityType" minOccurs="0" />
        <xsd:element name="Message"  type="MessageType" />
      </xsd:sequence>
      <xsd:anyAttribute namespace="##other" processContents="lax" />
    </xsd:complexType>
  </xsd:element>

  <xsd:simpleType name="ActionType">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="write"/>
      <xsd:enumeration value="read"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:complexType name="SecurityType">
    <xsd:sequence>
      <xsd:element ref="ds:Signature"       minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element ref="xenc:EncryptedKey"  minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element ref="xenc:ReferenceList" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:anyAttribute namespace="##other" processContents="lax" />
  </xsd:complexType>

  <xsd:complexType name="MessageType">
    <xsd:sequence>
      <xsd:element name="Header" type="HeaderType" minOccurs="0"/>
      <xsd:element name="Body"   type="BodyType" />
    </xsd:sequence>
    <xsd:anyAttribute namespace="##other" processContents="lax"  />
  </xsd:complexType>

  <xsd:complexType name="HeaderType" >
    <xsd:sequence>
      <xsd:element name="From" type="xsd:anyURI" minOccurs="0" />
      <xsd:group ref="writeElements" minOccurs="0" />
      <xsd:group ref="securityElements" minOccurs="0" />
    </xsd:sequence>    
    <xsd:anyAttribute namespace="##other" processContents="lax" />
  </xsd:complexType>

  <xsd:group name="writeElements" >
    <xsd:sequence>
      <xsd:element name="To" type="xsd:anyURI"  maxOccurs="unbounded" />
      <xsd:group ref="replyElements" minOccurs="0" />
      <xsd:element name="RelatesTo" type="xsd:anyURI"  minOccurs="0" />
      <xsd:element name="ConversationId" type="xsd:anyURI"  minOccurs="0" />
    </xsd:sequence>
  </xsd:group>
  
  <xsd:group name="replyElements" >
    <xsd:sequence>
      <xsd:element name="ReplyTo" type="xsd:anyURI" />
      <xsd:element name="ReplyId" type="xsd:anyURI" />
    </xsd:sequence>
  </xsd:group>
  
  <xsd:group name="securityElements" >
    <xsd:sequence>
      <xsd:element name="UniqueId" type="xsd:anyURI" />
      <xsd:element name="Timestamp" type="TimestampType" />
    </xsd:sequence>
  </xsd:group>
  
  <xsd:complexType name="TimestampType">
    <xsd:sequence>
      <xsd:element name="Created" type="xsd:dateTime"/>
      <xsd:element name="Expires" type="xsd:dateTime" minOccurs="0"/>
    </xsd:sequence>
  </xsd:complexType>
  
  <xsd:complexType name="BodyType" >
    <xsd:choice>
      <xsd:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> 
    </xsd:choice>
    <xsd:attribute name="schemaType" type="schemaEnum" use="optional" default="none" />
    <xsd:anyAttribute namespace="##other" processContents="lax" />
  </xsd:complexType>

  <xsd:element name="Xquery" type="textType"/>
  
  <xsd:complexType name="textType" >
    <xsd:complexContent mixed="true" >
      <xsd:restriction base="xsd:anyType" >
        <xsd:sequence>
          <xsd:any processContents="skip" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
      </xsd:restriction>
    </xsd:complexContent>  
  </xsd:complexType>
  
  <xsd:simpleType name="schemaEnum" >
    <xsd:restriction base="xsd:string" >
      <xsd:enumeration value="xsd" />
      <xsd:enumeration value="relaxng" />
      <xsd:enumeration value="schematron" />
      <xsd:enumeration value="dtd" />
      <xsd:enumeration value="nvp" />
      <xsd:enumeration value="none" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:element name="ReadResponse" >
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Status" type="StatusType" />
        <xsd:any namespace="##any"   processContents="lax" minOccurs="0" maxOccurs="unbounded" /> 
      </xsd:sequence>
      <xsd:anyAttribute namespace="##other" processContents="lax" />
    </xsd:complexType>
  </xsd:element>

  <xsd:element name="WriteResponse" >
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Status" type="StatusType" />
      </xsd:sequence>
      <xsd:anyAttribute namespace="##other" processContents="lax" />
    </xsd:complexType>
  </xsd:element>

  <xsd:complexType name="StatusType" >
    <xsd:sequence>
      <xsd:element name="Code" type="xsd:unsignedShort" />
      <xsd:element name="Message"   type="xsd:string" />
    </xsd:sequence>
  </xsd:complexType>

</xsd:schema>