XML Serializer
http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Main
User Documentation

Serializers
Overview

Default
HTML Serializer

Core
XHTML Serializer
XML Serializer
Text Serializer
WAP/WML Serializer
SVG Serializer
SVG/XML Serializer
SVG/JPEG Serializer
SVG/PNG Serializer
SVG/TIFF Serializer
VRML Serializer
Link Serializer
Zip archive Serializer

Optional
PDF Serializer
PS Serializer
PCL Serializer
HSSF (XLS) Serializer

XML Serializer

The xml serializer is the simplest possible serializer. It generates an xml document from the sax events. This serializer is used for serializing to any XML document format, ie. SVG, WML, VRML, et. al.

  • Name : xml
  • Class: org.apache.cocoon.serialization.XMLSerializer
  • Cacheable: yes.
Sitemap Configuration

The XML Serializer is declared in the sitemap serializers section.

<map:serializers ...
...
  <map:serializer name="xml"
    src="org.apache.cocoon.serialization.XMLSerializer"
    mime-type="text/xml"  
    logger="sitemap.serializer.xml" 
    pool-grow="4" pool-max="32" pool-min="4">
    <!-- serializer configurations -->
...    
  </map:serializer>
...
        

XML Serializer can be configured, specifying elements inside of the <map:serializer> body.

Configuration Example

The following XML Serializer snippet is setting encoding configuration for the XML Serializer

<map:serializer name="xml"         
  src="org.apache.cocoon.serialization.XMLSerializer"
  mime-type="text/xml">
  <encoding>ISO-8859-1</encoding>
</map:serializer>
          

This configuration will result in xml output of the form

<?xml version="1.0" encoding="ISO-8859-1"?>
...
          

The XML Serializer accepts following configuration parameters. These configurations are not Xalan specific.

NameXalan Default ValueComment
cdata-section-elements none cdata-section-elements specifies a whitespace delimited list of the names of elements whose text node children should be output using CDATA sections. See section 16 of the XSL Transformations (XSLT) W3C Recommendation.
doctype-public none doctype-public specifies the public identifier to be used in the document type declaration.
doctype-system none doctype-system specifies the system identifier to be used in the document type declaration. See section 16 of the XSL Transformations (XSLT) W3C Recommendation
encoding none encoding specifies the preferred character encoding that the Transformer should use to encode sequences of characters as sequences of bytes. The value of the attribute should be treated case-insensitively. The value must only contain characters in the range #x21 to #x7E (i.e., printable ASCII characters). The value should either be a charset registered with the Internet Assigned Numbers Authority [IANA], [RFC2278] or start with X-. See section 16 of the XSL Transformations (XSLT) W3C Recommendation
indent yes A Flag for toggling indent. This flag toggles only if some elements should trigger a line break.
media-type media-type specifies the media type (MIME content type) of the data that results from outputting the result tree. The charset parameter should not be specified explicitly; instead, when the top-level media type is text, a charset parameter should be added according to the character encoding actually used by the output method. See section 16 of the XSL Transformations (XSLT) W3C Recommendation
method The method attribute identifies the overall method that should be used for outputting the result tree. Other non-namespaced values may be used, such as "xhtml", but, if accepted, the handling of such values is implementation defined. If any of the method values are not accepted and are not namespace qualified, then {@link javax.xml.transform.Transformer#setOutputProperty} or {@link javax.xml.transform.Transformer#setOutputProperties} will throw a {@link java.lang.IllegalArgumentException}. See section 16 of the XSL Transformations (XSLT) W3C Recommendation
omit-xml-declaration omit-xml-declaration specifies whether the XSLT processor should output an XML declaration; the value must be yes or no. See section 16 of the XSL Transformations (XSLT) W3C Recommendation
standalone standalone specifies whether the Transformer should output a standalone document declaration; the value must be yes or no. See section 16 of the XSL Transformations (XSLT) W3C Recommendation
version version specifies the version of the output method. When the output method is "xml", the version value specifies the version of XML to be used for outputting the result tree. The default value for the xml output method is 1.0. When the output method is "html", the version value indicates the version of the HTML. The default value for the xml output method is 4.0, which specifies that the result should be output as HTML conforming to the HTML 4.0 Recommendation [HTML]. If the output method is "text", the version property is ignored. See section 16 of the XSL Transformations (XSLT) W3C Recommendation

Note Former property buffer-size is deprecated, and is ignored.

The XML Serializer sets the method property to xml.

Pipeline Usage

Using the XML Serializer in a pipeline is just setting the serializer type to xml. The following code snippet uses the XML Serializer:

...
<map:match pattern="*.xml">
<map:generate...
...
<map:serialize type="xml"/>
...
      
Further Reading

The XML serializer is usable for serializing any SAX events to a plain xml output. The various xml documents requires in most cases a proper configuration of following parameters

  • doctype-public
  • doctype-system

Moreover the mime-type, and name attribute of the serializer definition shall be set propertly.

Read the XML serializer configuration user documentation for SVG/XML, and WML in order to understand using the XML serialiazer for serializing to some specific XML content type.

Copyright © 1999-2002 The Apache Software Foundation. All Rights Reserved.