net.sf.saxon.s9api
class Serializer extends Object implements Destination
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 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_".
Serialization parameters defined via this interface take precedence over any serialization parameters defined within the source of the query or stylesheet.
Nested Class Summary | |
---|---|
static class | Serializer.Property |
Method Summary | |
---|---|
void | close()
Close any resources associated with this destination |
Object | getOutputDestination()
Get the current output destination.
|
String | getOutputProperty(Serializer.Property property)
Get the value of a serialization property |
Receiver | getReceiver(Configuration config)
Return a receiver to which Saxon will send events. |
protected Receiver | getReceiver(Configuration config, Controller controller, Properties predefinedProperties)
Return a receiver to which Saxon will send events. |
void | setOutputFile(File file)
Set the destination of the serialized output, as a File.
|
void | setOutputProperty(Serializer.Property property, String value)
Set the value of a serialization property. |
void | setOutputStream(OutputStream stream)
Set the destination of the serialized output, as an OutputStream.
|
void | setOutputWriter(Writer writer)
Set the destination of the serialized output, as a Writer.
|
Returns: an OutputStream, Writer, or File, depending on the previous calls to Serializer, Serializer, or Serializer
Parameters: property the name of the required property
Returns: the value of the required property as a string, or null if the property has not been given any value.
Parameters: config The Saxon configuration. This is an internal implementation object held within the Processor
Returns: a receiver to which XML events will be sent
Parameters: config The Saxon configuration controller The Saxon controller for the transformation or query. May be null if unknown. predefinedProperties values of serialization properties defined within a query or stylesheet, which will be used in the event that no value for the corresponding property has been defined in the Serializer itself. May be null if no serialization properties have been predefined.
Returns: a receiver to which XML events will be sent
Calling this method has the side-effect of setting the current OutputWriter and OutputStream to null.
Parameters: file the File to which the serialized XML output will be written.
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.
Parameters: property The name of the property to be set value 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.
Throws: IllegalArgumentException if the value of the property is invalid. The property is validated individually; invalid combinations of properties will be detected only when the properties are actually used to serialize an XML event stream.
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.
Parameters: stream the OutputStream to which the serialized XML output will be written.
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.
Parameters: writer the Writer to which the serialized XML output will be written.