Implements a text serializer supporting both DOM and SAX
serializing. For usage instructions see
Serializer
.
If an output stream is used, the encoding is taken from the
output format (defaults to
UTF-8). If a writer is
used, make sure the writer uses the same encoding (if applies)
as specified in the output format.
The serializer supports both DOM and SAX. DOM serializing is done
by calling
TextSerializer
and SAX serializing is done by firing
SAX events and using the serializer as a document handler.
If an I/O exception occurs while serializing, the serializer
will not throw an exception directly, but only throw it
at the end of serializing (either DOM or SAX's
org.xml.sax.DocumentHandler.endDocument
.
characters
protected void characters(String text,
boolean unescaped)
throws IOException
characters
public void characters(char[] chars,
int start,
int length)
throws org.xml.sax.SAXException
- characters in interface BaseMarkupSerializer
comment
public void comment(char[] chars,
int start,
int length)
- comment in interface BaseMarkupSerializer
endElement
public void endElement(String tagName)
throws org.xml.sax.SAXException
- endElement in interface org.xml.sax.DocumentHandler
endElement
public void endElement(String namespaceURI,
String localName,
String rawName)
throws org.xml.sax.SAXException
- endElement in interface org.xml.sax.ContentHandler
endElementIO
public void endElementIO(String tagName)
throws IOException
processingInstructionIO
public void processingInstructionIO(String target,
String code)
throws IOException
- processingInstructionIO in interface BaseMarkupSerializer
serializeElement
protected void serializeElement(org.w3c.dom.Element elem)
throws IOException
Called to serialize a DOM element. Equivalent to calling startElement
, endElement
and serializing everything
inbetween, but better optimized.
- serializeElement in interface BaseMarkupSerializer
serializeNode
protected void serializeNode(org.w3c.dom.Node node)
throws IOException
Serialize the DOM node. This method is unique to the Text serializer.
- serializeNode in interface BaseMarkupSerializer
node
- The node to serialize
startDocument
protected void startDocument(String rootTagName)
throws IOException
Called to serialize the document's DOCTYPE by the root element.
This method will check if it has not been called before (
TextSerializer
),
will serialize the document type declaration, and will serialize all
pre-root comments and PIs that were accumulated in the document
(see
TextSerializer
). Pre-root will be serialized even if
this is not the first root element of the document.
startElement
public void startElement(String namespaceURI,
String localName,
String rawName,
org.xml.sax.Attributes attrs)
throws org.xml.sax.SAXException
- startElement in interface org.xml.sax.ContentHandler
startElement
public void startElement(String tagName,
org.xml.sax.AttributeList attrs)
throws org.xml.sax.SAXException
- startElement in interface org.xml.sax.DocumentHandler