public interface Serializer
To serialize a document using SAX events, create a compatible serializer
and pass it around as a DocumentHandler
. If an I/O error occurs while serializing, it will
be thrown by DocumentHandler.endDocument()
. The SAX serializer
may also be used as DTDHandler
, DeclHandler
and
LexicalHandler
.
To serialize a DOM document or DOM element, create a compatible
serializer and call it's DOMSerializer.serialize(Document)
or DOMSerializer.serialize(Element)
methods.
Both methods would produce a full XML document, to serizlie only
the portion of the document use OutputFormat.setOmitXMLDeclaration(boolean)
and specify no document type.
The OutputFormat
dictates what underlying serialized is used
to serialize the document based on the specified method. If the output
format or method are missing, the default is an XML serializer with
UTF-8 encoding and now indentation.
DocumentHandler
,
ContentHandler
,
OutputFormat
,
DOMSerializer
Modifier and Type | Method and Description |
---|---|
org.xml.sax.ContentHandler |
asContentHandler()
Return a
ContentHandler interface into this serializer. |
org.xml.sax.DocumentHandler |
asDocumentHandler()
Return a
DocumentHandler interface into this serializer. |
DOMSerializer |
asDOMSerializer()
Return a
DOMSerializer interface into this serializer. |
void |
setOutputByteStream(java.io.OutputStream output)
Specifies an output stream to which the document should be
serialized.
|
void |
setOutputCharStream(java.io.Writer output)
Specifies a writer to which the document should be serialized.
|
void |
setOutputFormat(OutputFormat format)
Specifies an output format for this serializer.
|
void setOutputByteStream(java.io.OutputStream output)
void setOutputCharStream(java.io.Writer output)
void setOutputFormat(OutputFormat format)
format
- The output format to useorg.xml.sax.DocumentHandler asDocumentHandler() throws java.io.IOException
DocumentHandler
interface into this serializer.
If the serializer does not support the DocumentHandler
interface, it should return null.java.io.IOException
org.xml.sax.ContentHandler asContentHandler() throws java.io.IOException
ContentHandler
interface into this serializer.
If the serializer does not support the ContentHandler
interface, it should return null.java.io.IOException
DOMSerializer asDOMSerializer() throws java.io.IOException
DOMSerializer
interface into this serializer.
If the serializer does not support the DOMSerializer
interface, it should return null.java.io.IOException
Copyright © 2010 - 2020 Adobe. All Rights Reserved