|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.saxon.s9api.Serializer
public class Serializer
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 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_".
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
Enumerator over the defined serialization properties |
Constructor Summary | |
---|---|
Serializer()
Create a Serializer |
|
Serializer(File file)
Create a Serializer initialized to write to a given File. |
|
Serializer(OutputStream stream)
Create a Serializer initialized to write to a given OutputStream. |
|
Serializer(Writer writer)
Create a Serializer initialized to write to a given Writer. |
Method Summary | |
---|---|
void |
close()
Close any resources associated with this destination. |
Object |
getOutputDestination()
Get the current output destination. |
protected Properties |
getOutputProperties()
Create a Properties object holding the defined serialization properties. |
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(Executable executable)
Return a receiver to which Saxon will send events. |
protected Result |
getResult()
Get the JAXP StreamResult object representing the output destination of this serializer |
XMLStreamWriter |
getXMLStreamWriter()
Get an XMLStreamWriter that can be used for writing application-generated XML to be output via this serializer. |
void |
serializeNode(XdmNode node)
Serialize an XdmNode to the selected output destination using this serializer |
String |
serializeNodeToString(XdmNode node)
Serialize an XdmNode to a string using this serializer |
void |
serializeXdmValue(XdmValue value)
Serialize an arbitrary XdmValue to the selected output destination using this serializer. |
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. |
void |
setProcessor(Processor processor)
Set the Processor associated with this Serializer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Serializer()
public Serializer(OutputStream stream)
Closing the output stream after use is the responsibility of the caller.
stream
- The OutputStream to which the Serializer will writepublic Serializer(Writer writer)
Closing the writer after use is the responsibility of the caller.
writer
- The Writer to which the Serializer will writepublic Serializer(File file)
file
- The File to which the Serializer will writeMethod Detail |
---|
public void setProcessor(Processor processor)
Processor.newSerializer()
methods. The Serializer
currently needs to know about the Processor only if the method getXMLStreamWriter()
is called.
processor
- the associated Processorpublic void setOutputProperty(Serializer.Property property, String value)
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.
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.public String getOutputProperty(Serializer.Property property)
property
- the name of the required property
public void setOutputWriter(Writer 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.public void setOutputStream(OutputStream 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.
stream
- the OutputStream to which the serialized XML output will be written.public void setOutputFile(File 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.public void serializeNode(XdmNode node) throws SaxonApiException
node
- The node to be serialized
IllegalStateException
- if no outputStream, Writer, or File has been supplied as the
destination for the serialized output
SaxonApiException
- if a serialization error or I/O error occurspublic void serializeXdmValue(XdmValue value) throws SaxonApiException
value
- The value to be serialized
IllegalStateException
- if no outputStream, Writer, or File has been supplied as the
destination for the serialized output, or if no Processor is associated with the serializer
SaxonApiException
- if a serialization error or I/O error occurspublic String serializeNodeToString(XdmNode node) throws SaxonApiException
node
- The node to be serialized
SaxonApiException
- if a serialization error occurspublic XMLStreamWriter getXMLStreamWriter() throws SaxonApiException
IllegalStateException
- if no Processor has been set for this Serializer
SaxonApiException
- if any other failure occurspublic Object getOutputDestination()
setOutputStream(java.io.OutputStream)
, setOutputWriter(java.io.Writer)
, or setOutputFile(java.io.File)
; or
null, if no output destination has been set up.public Receiver getReceiver(Configuration config) throws SaxonApiException
getReceiver
in interface Destination
config
- The Saxon configuration. This is an internal implementation object
held within the Processor
SaxonApiException
- if the Receiver cannot be createdprotected Receiver getReceiver(Executable executable) throws SaxonApiException
executable
- The Saxon Executable for the transformation or query. The serialization
properties defined in this Serializer are supplemented by properties that have been
defined in the query or stylesheet associated with the Executable. The properties defined
in this Serializer take precedence over those in the stylesheet or query.
SaxonApiException
- if any failure occursprotected Properties getOutputProperties()
Transformer.getOutputProperties()
protected Result getResult()
public void close() throws SaxonApiException
close
in interface Destination
SaxonApiException
- if any failure occurs
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |