![]() | ![]() | SerializersSerializers take the pipeline data as a DOM document and output it to the client. There are four basic types at present supported within Paloose:
Component DeclarationSerializers are defined in the component declaration part of the Sitemap. <map:serializers default="xml">
<map:serializer name="html" src="resource://lib/serialization/HTMLSerializer">
<doctype-public>-//W3C//DTD HTML 4.01 Transitional//EN</doctype-public>
<doctype-system>http://www.w3.org/TR/html4/loose.dtd</doctype-system>
<encoding>iso-8859-1</encoding>
</map:serializer>
<map:serializer name="xhtml" src="resource://lib/serialization/XHTMLSerializer">
<doctype-public>-//W3C//DTD XHTML 1.0 Strict//EN</doctype-public>
<doctype-system>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</doctype-system>
<encoding>iso-8859-1</encoding>
</map:serializer>
<map:serializer name="text" src="resource://lib/serialization/TextSerializer"/>
<map:serializer name="xml" src="resource://lib/serialization/XMLSerializer"/>
</map:serializers> The default attribute specifies the type of serializer to use if none is specified in a pipeline. HTMLSerializerSerializers are the last part of a pipeline (unless there is a reader or mount pipeline element). So a typical use of HTMLSerializer would be <map:components>
...
<map:serializers default="xml">
<map:serializer name="html" mime-type="text/html" src="resource://lib/serialization/HTMLSerializer">
<doctype-public>-//W3C//DTD HTML 4.01 Transitional//EN</doctype-public>
<doctype-system>http://www.w3.org/TR/html4/loose.dtd</doctype-system>
<encoding>iso-8859-1</encoding>
</map:serializer>
</map:serializers>
</map:components>
<map:pipelines>
<map:pipeline>
<map:match pattern="*.html">
<!-- generate -->
<!-- some transformations -->
<map:serialize type="html"/>
</map:match>
</map:pipeline>
</map:pipelines> Given that the last transformer gave HTML as an output the HTML serializer would produce the following typical output:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- Remaining head tags from DOM -->
</head>
<body>
<!-- Remaining body tags from DOM -->
</body>
</html> XHTMLSerializer UsageXHTMLSerializers are similar to the HTMLSerializer except that they produce valid XHTML as an XML document. For example: <map:components>
...
<map:serializers default="xml">
<map:serializer name="xhtml" mime-type="text/html" src="resource://lib/serialization/XHTMLSerializer">
<doctype-public>-//W3C//DTD XHTML 1.0 Strict//EN</doctype-public>
<doctype-system>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</doctype-system>
<encoding>iso-8859-1</encoding>
</map:serializer>
</map:serializers>
</map:components>
<map:pipelines>
<map:pipeline>
<map:match pattern="*.html">
<!-- generate -->
<!-- some transformations -->
<map:serialize type="html"/>
</map:match>
</map:pipeline>
</map:pipelines> Again, given a suitable HTML input this would produce: <?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- Remaining head tags from DOM -->
</head>
<body>
<!-- Remaining body tags from DOM -->
</body>
</html> <map:components>
...
<map:serializers default="xml">
<map:serializer name="xhtml" src="resource://lib/serialization/XHTMLSerializer">
<doctype-public>-//W3C//DTD XHTML 1.0 Strict//EN</doctype-public>
<doctype-system>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</doctype-system>
<encoding>iso-8859-1</encoding>
</map:serializer>
</map:serializers>
</map:components>
<map:pipelines>
<map:pipeline>
<map:match pattern="*.html">
<!-- generate -->
<!-- some transformations -->
<map:serialize type="html"/>
</map:match>
</map:pipeline>
</map:pipelines> TextSerializer UsageThere are occasions where it is useful, to output pure text, particularly on internal pipelines that return data to another pipeline (aggregation etc). For this the TextSerializer is used. <map:components>
...
<map:serializers default="xml">
<map:serializer name="text" src="resource://lib/serialization/TextSerializer"/>
</map:serializers>
</map:components>
<map:pipelines>
<map:pipeline>
<map:match pattern="*.html">
<!-- generate -->
<!-- some transformations -->
<map:serialize type="text"/>
</map:match>
</map:pipeline>
</map:pipelines> The output from this would be the text content from all the DOM document tags. XMLSerializer UsageIt is also possible to output the XML within the DOM in the pipeline directly. This is of use in the aggregation process when a document is made up of several XML parts. As an example consider this from the Paloose site content sitemap <map:components>
...
<map:serializers default="xml">
<map:serializer name="xhtml" src="resource://lib/serialization/XHTMLSerializer">
<doctype-public>-//W3C//DTD XHTML 1.0 Strict//EN</doctype-public>
<doctype-system>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</doctype-system>
<encoding>iso-8859-1</encoding>
</map:serializer>
<map:serializer name="xml" src="resource://lib/serialization/XMLSerializer"/>
</map:serializers>
</map:components>
<map:pipelines>
<map:pipeline>
<map:match pattern="**.html">
<map:aggregate element="root" label="aggr-content">
<map:part src="cocoon:/menus.xml" element="menus" strip-root="true"/>
...
</map:aggregate>
...
<map:serialize type="xhtml" />
</map:match>
<map:match pattern="menus.xml">
<map:generate src="context://content/menus.xml" label="menus-content"/>
<map:transform type="i18n">
<map:parameter name="default-catalogue-id" value="menus"/>
</map:transform>
<map:serialize/>
</map:match>
</map:pipelines> The output menus matcher would give the following into the aggregator: <?xml version="1.0"?>
<page:page xmlns:link="http://www.hsfr.org.uk/Schema/Link"
xmlns:list="http://www.hsfr.org.uk/Schema/List"
... >
...
</page:page> | ![]() |


