Serving "application/tei+xml" from Cocoon

Most websites which publish TEI XML documents describe them with the content type "application/xml" or "text/xml". These are two labels for XML files in general, and don't identify the files as specifically TEI XML. By using the content type "application/tei+xml", a webserver can make the specific claim that the XML file is TEI rather than any other kind of XML. This has the advantage that browsers can be configured to handle TEI files distinctly from the way they handle other XML files (for instance, by opening them in an XML editor).

This page describes how to configure Apache Cocoon to serve TEI content as "application/tei+xml".

= Simple configuration =

To specify the content type, simply configure a TEI XML serializer in your sitemap.xmap file, and then invoke the serializer in your TEI pipelines.

To declare the serializer:



To invoke the serializer:

This configuration will always send the TEI using the "application/tei+xml" content type. However, this may not be ideal for browsers which are not configured to handle it.

= Preferred configuration =

Most browsers will adequately display generic XML but will not be configured to handle the specific content type "application/tei+xml". For this reason, it's usually better to serve the TEI as "application/tei+xml" only if the browser specifically asks for it, and otherwise to serve it as the generic "application/xml".

In Cocoon, you can use a RegexpHeaderSelector to determine if a browser is prepared to handle the specific content type. The following Cocoon sitemap file shows:


 * A plain XML serializer
 * A TEI XML serializer
 * A selector for determining if a browser will accept "application/tei+xml"
 * A pipeline fragment ("resource") which uses the selector to determine if a browser will accept "application/tei+xml", and uses the appropriate XML serializer
 * A pipeline which invokes the above resource instead of just invoking a serializer directly

     application/tei\+xml accept

 

  

Configuring your browser to request "application/tei+xml"
Using this configuration, you will need to configure your browser to declare that it's prepared to accept "application/tei+xml".

To configure Firefox, enter "about:config" into the address bar, find the key called "network.http.accept.default" and change it to include "application/tei+xml" in the list of acceptable content types, e.g.:

text/html;q=0.7,application/xhtml+xml;q=0.8,application/tei+xml;q=0.7,application/xml;q=0.6,*/*;q=0.4,application/json;q=0.5