XMLPatterns.com

Envelope

Abstract

Provide a document type which is defined to be a holder for other, arbitrary XML data.

Problem

Different sets of data need to be delivered to a system in a consistent way.

Context

This pattern applies when different sets of data need to be used in some system. The structure of the data itself varies, or is not known at the time the system is being built.

Forces

This pattern allows for Flexibility by allowing elements from other documents to be embedded into a consistent holder.
This pattern allows for a separation of concerns between different document types. Mixing issues such as transport with document data is usually not a good idea.

Solution

Create a document type which will act as a holder for the varying set of data.

Examples

This example shows a very simple envelope which consists of sender and a receiver children elements. Note the use of two different namespaces to allow an XML parser to read the document, which contains elements from both the Envelope (envelope.dtd) and the embedded data (my-stuff.dtd)
        

<e:Envelope xmlsns:e="http://xmlpatterns.com/envelope.dtd">
<e:sender name="bob"/>
<e:receiver name="http://xmlpatterns.com/message-receiver.cgi"/>
<myStuff:message xmlsns:e="http://xmlpatterns.com/my-stuff.dtd">
This is my message
</myStuff:message>
</e:Envelope>

        
      

Discussion

The Envelope is used as a delivery mechanism for XML data. Document types created for holding domain data should not be responsible, for defining transport ways to do deal with things such as transport, security, delivery and packaging. The envelope provide for a clear separation between these things and the data itself.

Related Patterns

This is similar to the Catch-All Element, except that the the document type of the Envelope pattern exists solely as an holder for other data and, the Catch-All Element is for embedding new elements within exsisting data.

Known Uses

SOAP (Simple Object Access Protocol) (http://www.w3.org/TR/SOAP/) is an Envelope for doing remote transport of messages.

References