<?xml version="1.0"?>

<schema xmlns="http://www.w3.org/1999/XMLSchema" targetNamespace="urn:x-lexica:xmsg:message:1.0" xmlns:xmsg="urn:x-lexica:xmsg:message:1.0">
   
   <annotation>
   <documentation>
      <title xmlns="http://www.w3.org/1999/xhtml">XML Message Schema</title> 
      <body xmlns="http://www.w3.org/1999/xhtml"> 
         <p>This schema defines the message format for the XML Messaging Specification (XMSG).  It provides the ability to encode multiple XML documents, non-XML documents, and metadata about the message or documents themselves.</p>
         <p>The root of the message is the <a href="@element.decl.message">message</a> element.</p>
      </body>
   </documentation>
   </annotation>

   <element name="message" type="xmsg:message">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>The element for encoding a message.</p>
        </body>
      </documentation>
      </annotation>
   </element>
   <element name="hop" type="xmsg:hop">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>The element for encoding a message hop.</p>
        </body>
      </documentation>
      </annotation>
   </element>
   <element name="property" type="xmsg:property">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>The element for encoding a message or document property.</p>
        </body>
      </documentation>
      </annotation>
   </element>
   <element name="document" type="xmsg:document">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>The element for encoding a document.</p>
        </body>
      </documentation>
      </annotation>
   </element>
   <element name="failure" type="xmsg:failure">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>The element for encoding a message failure.</p>
        </body>
      </documentation>
      </annotation>
   </element>
   <element name="receipt" type="xmsg:receipt">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>The element for encoding a message receipt.</p>
        </body>
      </documentation>
      </annotation>
   </element>
   <element name="content" type="xmsg:content">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>The element for encoding an XML document.</p>
        </body>
      </documentation>
      </annotation>
   </element>
   <element name="data" type="xmsg:data">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>The element for encoding a non-XML document.</p>
        </body>
      </documentation>
      </annotation>
   </element>
   <element name="data.reference" type="xmsg:data.reference">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>The element for referencing "out-of-band" documents.</p>
        </body>
      </documentation>
      </annotation>
   </element>

   <complexType name="message" content="elementOnly">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>A message may consist of an set of XML documents, non-XML documents, or references to "out-of-band" documents.</p> 
        <p>As a document is routed through a system to a target participant--as identified by the "to" property--a set of "system hops" encoded as hop elements may be added the message by the processing application.  This encodes an audit trail for where the message has been.</p>
        <p>A message also has properties associated with it.  These properties are either first-class or arbitrary (application-defined).  Any first-class property is encoded as an attribute and has a semantic defined in the XMSG specification.</p>
        <p>In addition, each document may have properties.  These properties may also be first-class or arbitrary (application-defined).  A document's properties also specify the identity of the document.</p>
        <p>The message may also specify a manifest, which is a pointer to a document that describes the contents of the message. The specification of the content of the manifest is left to the application or layered protocol.</p>
        </body>
      </documentation>
      </annotation>
      <sequence minOccurs="1" maxOccurs="1">
         <element ref="hop" minOccurs="0" maxOccurs="unbounded"/>
         <element ref="property" minOccurs="0" maxOccurs="unbounded"/>
         <choice minOccurs="1" maxOccurs="1">
            <element ref="document" minOccurs="1" maxOccurs="unbounded"/>
            <element ref="receipt" minOccurs="1" maxOccurs="1"/>
            <element ref="failure" minOccurs="1" maxOccurs="1"/>
         </choice>
      </sequence>
      <attribute name="from" use="required" type="xmsg:absoluteURI">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Identifies the sender of the message via a URI value.  This value must be absolute.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="to" use="required" type="xmsg:absoluteURI">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Identifies the intended recipiant of the message via a URI value.  This value must be absolute.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="reply.to" type="xmsg:absoluteURI">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Identifies to whom the reply should be send via a URI.  Typically, this value is copied to the "to" attribute of the reply message.  This value must be absolute.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="originator" type="xmsg:absoluteURI">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Identifies for whom the message was sent of behalf of by the sender via a URI value.  This value must be absolute.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="originator.id" type="xmsg:nonEmptyString">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>A unique identifier that, when paired with the originator value, should be unique over time for the originator.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="action" type="xmsg:nonEmptyString">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>An application-dependent value that further qualifies to process to be performed by the recipiant.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="priority" use="default" value="normal">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Identifies the priority level at which the recipiant should process the message.</p>
            </body>
         </documentation>
         </annotation>
         <simpleType base="string">
            <enumeration value="lowest">
               <annotation>
               <documentation>
               <body xmlns="http://www.w3.org/1999/xhtml">
               <p>Sets the message processing to lowest priority.</p>
               </body>
               </documentation>
               </annotation>
            </enumeration>
            <enumeration value="low">
               <annotation>
               <documentation>
               <body xmlns="http://www.w3.org/1999/xhtml">
               <p>Sets the message processing to low priority.</p>
               </body>
               </documentation>
               </annotation>
            </enumeration>
            <enumeration value="normal">
               <annotation>
               <documentation>
               <body xmlns="http://www.w3.org/1999/xhtml">
               <p>Sets the message processing to normal priority.</p>
               </body>
               </documentation>
               </annotation>
            </enumeration>
            <enumeration value="high">
               <annotation>
               <documentation>
               <body xmlns="http://www.w3.org/1999/xhtml">
               <p>Sets the message processing to high priority.</p>
               </body>
               </documentation>
               </annotation>
            </enumeration>
            <enumeration value="highest">
               <annotation>
               <documentation>
               <body xmlns="http://www.w3.org/1999/xhtml">
               <p>Sets the message processing to highest priority.</p>
               </body>
               </documentation>
               </annotation>
            </enumeration>
         </simpleType>
      </attribute>
      <attribute name="expires" type="timeInstant">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Identifies a date and time in the future at which the message should be consider expired and no longer relavant.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="id" use="required" type="xmsg:nonEmptyString">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>An identifier that, when paired with the from value (sender), should be unique over time for the sender.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="tracking.code" type="xmsg:nonEmptyString">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>An application-dependent tracking code that can be used to track transactions, etc. over multiple messages.  This value is not necessarily unique to a specific message instance.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="generated.on" use="required" type="timeInstant">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>The date and time the message was generated by the sender.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="manifest" type="xmsg:absoluteURI">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>The URI of the document in the message that should be considered a manifest.  The syntax and semantics of this message is application-dependent.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="receipt.required" type="boolean" use="default" value="false">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Identifies that a receipt for this message is requested because asynchronous processing of the reply will occurr.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="for.receipt" type="xmsg:nonEmptyString">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Identifies the receipt for which this message is a reply.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
   </complexType>

   <complexType name="hop" content="empty">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This type represents a routing hop between nodes in a system.  Essentially, this type records a specific hop in an audit trail for where the message has been.</p>
        </body>
      </documentation>
      </annotation>
      <attribute name="received.on" use="required" type="timeInstant">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Identifies the date upon which the message was received.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="received.by" use="required" type="xmsg:absoluteURI">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Identifies the host or system that received the message.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="transport.method" use="required" type="xmsg:nonEmptyString">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Identifies the transport method used in this hop.  Typically, this value is some code list "http" or "https".</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
   </complexType>

   <complexType name="property" content="empty">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This type encodes a specific metadata property as a name/value pair.</p>
        </body>
      </documentation>
      </annotation>
      <attribute name="name" use="required" type="QName">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Identifies the name of the property.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="value" use="required" type="xmsg:nonEmptyString">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>Specifies the value to be associated with this property.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
   </complexType>

   <complexType name="document" content="elementOnly">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This type represents a document encoded within a message.  This document may be an inline XML document, an inline non-XML document, or an out-of-band XML document via a reference.  In all cases, a set of properties may be associated with the document.</p>
        <p>The "uri" attribute identifies the URI of the document.  This URI must be unique to the message and should be considered the identity of the document.  In this way, the URI can be use to match document between the sender and receiver.</p>
        </body>
      </documentation>
      </annotation>
      <sequence minOccurs="1" maxOccurs="1">
         <element ref="property" minOccurs="0" maxOccurs="unbounded"/>
         <choice minOccurs="1" maxOccurs="1">
            <element ref="content" minOccurs="1" maxOccurs="1"/>
            <element ref="data" minOccurs="1" maxOccurs="1"/>
            <element ref="data.reference" minOccurs="1" maxOccurs="1"/>
         </choice>
      </sequence>
      <attribute name="uri" use="required" type="xmsg:absoluteURI">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>The URI to be used to identify the contained or referred document.  This value must be absolute.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="version" type="string">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>An application-dependent version string for this document.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
   </complexType>

   <complexType name="content" content="elementOnly">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This type encodes an inline XML document.  The first and only child is a the document element of the embedded XML document.</p>
        </body>
      </documentation>
      </annotation>
      <any maxOccurs="1" namespace="##any" processContents="lax"/>
   </complexType>

   <complexType name="data" content="textOnly">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This type encodes the non-XML data using some encoding scheme.  The content of this type is the encoded data.</p>
        </body>
      </documentation>
      </annotation>
      <attribute name="content.type" use="required" type="xmsg:mimeType">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>The content type of the enclosed data.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="encoding" use="required" type="string">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>The encoding of the enclosed data (e.g. base64, etc.).</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
   </complexType>

   <complexType name="data.reference" content="empty">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This type encodes a reference to an "out-of-band" document.  Such a document exists external to the message and is transport dependant on how it is resolved.  This document may be XML or non-XML.</p>
        </body>
      </documentation>
      </annotation>
      <attribute name="href" use="required" type="uriReference">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>The URI of the referenced document.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="content.type" use="required" type="xmsg:mimeType">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>The MIME type of the referenced document.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="encoding" type="string">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>The encoding of the referenced document.  This property maybe defaulted to the protocol used to access the document.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
   </complexType>

   <complexType name="failure" content="textOnly">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This type represents a failure message.  The contents of the message is the "human readable" portion of the failure.</p>
        </body>
      </documentation>
      </annotation>
      <attribute name="on" type="timeInstant" use="required">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>The time at which the failure occurred.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="status.code" type="string">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>An application-dependent status code.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
   </complexType>

   <complexType name="receipt" content="empty">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This type represents a receipt for message.  It is used for asynchrous messages.</p>
        </body>
      </documentation>
      </annotation>
      <attribute name="timestamp" type="timeInstant" use="required">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>The date and time of the receipt as generated by the system which received the message to which this is a receipt.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
      <attribute name="message.tracking.code" type="xmsg:nonEmptyString" use="required">
         <annotation>
         <documentation>
            <body xmlns="http://www.w3.org/1999/xhtml">
            <p>A message tracking code to be used to match a future message with a "for.receipt" value of the same value.</p>
            </body>
         </documentation>
         </annotation>
      </attribute>
   </complexType>

   <simpleType name="absoluteURI" base="uriReference">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This simple type represents an absolute URI.</p>
        </body>
      </documentation>
      </annotation>
      <pattern value="\c+:.+"/>
   </simpleType>

   <simpleType name="nonEmptyString" base="string">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This simple type represents a string with at least one character.</p>
        </body>
      </documentation>
      </annotation>
      <pattern value=".+"/>
   </simpleType>

   <simpleType name="mimeType" base="string">
      <annotation>
      <documentation>
        <body xmlns="http://www.w3.org/1999/xhtml">
        <p>This simple type represents a MIME type specification.</p>
        </body>
      </documentation>
      </annotation>
      <pattern value="\c+/\c+"/>
   </simpleType>

</schema>
