apache > cocoon

Cocoon Sitemap Serializer FAQs

What is a serializer?

A serializer is the end point of an xml pipeline. It transforms SAX events into binary or char streams for final client consumption. Every pipeline match containing a generator must be terminated by a serializer.

In the sitemap file, each serializer has a unique name which is mapped to a java class. One serializer name must be declared as the default serializer. Each serializer may have additional configuration information specified in child elements.

For more conceptual information about serializers see the sitemap. For detailed descriptions about all of the available Cocoon serializers, see the user's guide document Serializers in Cocoon. You may also wish to consult the Cocoon API documentation.

What is the easiest way to generate XHTML output?

I have an stylesheet which transforms XML to XHTML, but it seems that the serializer converts it to HTML. For example, I have some <br/> elements which are converted to <br> elements. What can I do?

Cocoon has serializer configured for XHTML. First, make sure to declare it in your sitemap's component section (within map:serializers).

<map:serializer name="xhtml" mime-type="text/html"
  <doctype-public>-//W3C//DTD XHTML 1.0 Strict//EN</doctype-public>

Then, in any pipeline, simply use the serializer as follows.

<map:serialize type="xhtml" />

How can I remove the DTD declaration at the top of my HTML pages created from pipelines with the default (HTML) serializer?

Within the map:components section of sitemap.xmap, adjust the configuration of your HTML serializer component as follows.

<map:serializers default="html">

  <map:serializer name="html" mime-type="text/html; charset=ISO-8859-1"
  <!-- other serializers -->
Consider using the XMLSerializer in your pipeline. The XMLSerializer will not write a DocType Declaration.

How can I remove namespaces from my xml files?

Sometimes adding xsl:exclude-result-prefixes attributes to the <xsl:stylesheet> or literal result element is not effective in removing all namespace declarations. For example, namespace nodes copied from the source document within <xsl:copy> or <xsl:copy-of> instructions (commonly found in catch-all stylesheet templates) will not be excluded.

There are two approaches to this problem.

One approach is to extend your serializer component and override the startPrefixMapping and endPrefixMapping methods to do nothing. This will remove all namespaces from the serialized output. Since your serializer will no longer be processing namespaces, this theoretically will improve performance ever so slightly. You could generalize this approach by using the serializer's configuration method to declare namespaces to be excluded.

Another approach is to use an interim transformation step in your pipeline with a stylesheet described here.