net.sf.saxon.s9api
Class Serializer
java.lang.Object
net.sf.saxon.s9api.Serializer
- Destination
public class Serializer
extends java.lang.Object
A Serializer takes a tree representation of XML and turns it into lexical XML markup.
Note that this is XML serialization in the sense of the W3C XSLT and XQuery specifications.
This has nothing to do with the serialization of Java objects, or the java.io.Serializable
interface.
The serialization may be influenced by a number of serialization parameters. A parameter has a name,
which is an instance of
Serializer.Property
, and a value, which is expressed as a string.
The effect of most of the properties is as described in the W3C specification
XSLT 2.0 and XQuery 1.0 Serialization.
Saxon supports all the serialization parameters defined in that specification, together with some
additional parameters, whose property names are prefixed "SAXON_".
getOutputDestination
public Object getOutputDestination()
Get the current output destination.
getOutputProperty
public String getOutputProperty(Serializer.Property property)
Get the value of a serialization property
property
- the name of the required property
- the value of the required property as a string, or null if the property has
not been given any value.
getReceiver
public Receiver getReceiver(Configuration config)
throws SaxonApiException
Return a receiver to which Saxon will send events. This method is provided
primarily for system use, though it could also be called by user applications
wanting to make use of the Saxon serializer.
- getReceiver in interface Destination
config
- The Saxon configuration. This is an internal implementation object
held within the Processor
- a receiver to which XML events will be sent
setOutputFile
public void setOutputFile(File file)
Set the destination of the serialized output, as a File.
Calling this method has the side-effect of setting the current OutputWriter
and OutputStream to null.
file
- the File to which the serialized XML output will be written.
setOutputProperty
public void setOutputProperty(Serializer.Property property,
String value)
Set the value of a serialization property. Any existing value of the property is overridden.
If the supplied value is null, any existing value of the property is removed.
Example:
serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
Any serialization properties supplied via this interface take precedence over serialization
properties defined in the source stylesheet or query.
property
- The name of the property to be setvalue
- The value of the property, as a string. The format is generally as defined
in the xsl:output
declaration in XSLT: this means that boolean properties, for
example, are represented using the strings "yes" and "no". Properties whose values are QNames,
such as cdata-section-elements
are expressed using the Clark representation of
a QName, that is "{uri}local". Multi-valued properties (again, cdata-section-elements
is an example) are expressed as a space-separated list.
setOutputStream
public void setOutputStream(OutputStream stream)
Set the destination of the serialized output, as an OutputStream.
Closing the output stream after use is the responsibility of the caller.
Calling this method has the side-effect of setting the OutputWriter and OutputFile to null.
stream
- the OutputStream to which the serialized XML output will be written.
setOutputWriter
public void setOutputWriter(Writer writer)
Set the destination of the serialized output, as a Writer.
Note that when this option is used, the serializer does not perform character
encoding. This also means that it never replaces special characters with XML numeric
character references. The final encoding is the responsibility of the supplied Writer.
Closing the writer after use is the responsibility of the caller.
Calling this method has the side-effect of setting the OutputStream and OutputFile to null.
writer
- the Writer to which the serialized XML output will be written.