Search code examples
httpmime-types

Streaming XML Mime Type?


I'm building a web service that emits streaming XML. So, the output will look (at a high level) like this:

<fragment1>
    <!-- ... -->
</fragment1>

<fragment2>
    <!-- ... -->
</fragment2>

...and so on. For a normal XML document, you'd use any one of these different MIME types:

  • application/xml
  • application/vnd.mycompany.com.description+xml (per this lovely answer)
  • text/xml

However, those MIME types all assume that the response contains exactly one XML document/fragment. In my case, the response contains zero or more fragments. For this reason, it seems like The Wrong Thing to use one of those MIME types. A correct handler would (correctly) handle the response as a single XML document and either (a) barf upon arriving at the second fragment, or (b) silently ignore fragments starting at fragment 2.

If that's The Wrong Thing, is one of these MIME types The Right Thing:

  1. application/octet-stream
  2. application/vnd.mycompany.com.description.streaming+xml
  3. application/vnd.mycompany.com.description+streaming-xml

Or should I use a completely different one? Also, it would be great if the same "style" of MIME type could be applied to streaming JSON once that data format comes online.

EDIT: To give a little more flavor to the question and provide an example of a working implementation I'm trying to emulate, this API is modelled after the Twitter streaming API.


Solution

  • Sounds like apart from your streaming requirements, your content is actually a Multipart message with several application/xml parts. With this layout application/json parts could also be mixed in your message.

    If your individual XML Fragments are part of larger documents take a look at the (somewhat old and understated) XML Fragment Interchange W3C Candidate Recommendation. It defines a nice syntax to wrap fragment bodies together with contextual information about the original document.