public class ToXmlContentHandler
extends org.xml.sax.helpers.DefaultHandler
Writer
or OutputStream
.
The serialization assumes that the incoming SAX events are well-formed,
i.e. that all elements are properly nested, that element and attribute
names are valid and that no invalid XML characters are included. Assuming
these preconditions are met, the result will be a well-formed XML stream.
This serializer does not have any special support for namespaces. For
example, namespace prefixes are declared in the resulting XML stream
if and only if the corresponding "xmlns" attributes are explicitly
included in the Attributes
instances passed in
startElement(String, String, String, Attributes)
calls.
As a convenience this class inherits the DefaultHandler
class
instead of just the ContentHandler
interface. This makes it
easier to pass instances of this class to methods like
SAXParser.parse(String, DefaultHandler)
that
expect a DefaultHandler instance instead of a ContentHandler.
Constructor and Description |
---|
ToXmlContentHandler()
Creates an XML serializer that writes the serialized XML stream
to an internal buffer.
|
ToXmlContentHandler(java.io.OutputStream stream)
Creates an XML serializer that writes the serialized XML stream
to the given output stream using the UTF-8 character encoding.
|
ToXmlContentHandler(java.io.OutputStream stream,
java.lang.String encoding)
Creates an XML serializer that writes the serialized XML stream
to the given output stream using the given character encoding.
|
ToXmlContentHandler(java.io.Writer writer)
Creates an XML serializer that writes the serialized XML stream
to the given writer.
|
Modifier and Type | Method and Description |
---|---|
void |
characters(char[] ch,
int start,
int length)
Escapes and outputs the given characters.
|
void |
endDocument()
Ends the XML serialization by flushing the output stream.
|
void |
endElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
Outputs the specified end tag.
|
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Escapes and outputs the given characters.
|
void |
processingInstruction(java.lang.String target,
java.lang.String data)
Serializes a processing instruction.
|
void |
startDocument()
Starts the XML serialization by outputting the <?xml?> header.
|
void |
startElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes atts)
Outputs the specified start tag with the given attributes.
|
java.lang.String |
toString()
Returns the serialized XML document (assuming the default no-argument
constructor was used).
|
public ToXmlContentHandler(java.io.OutputStream stream, java.lang.String encoding) throws java.io.UnsupportedEncodingException
stream
- XML output streamencoding
- character encodingjava.io.UnsupportedEncodingException
- if the encoding is not supportedpublic ToXmlContentHandler(java.io.OutputStream stream)
stream
- XML output streampublic ToXmlContentHandler(java.io.Writer writer)
writer
- XML output streampublic ToXmlContentHandler()
toString()
method to access
the serialized XML document.public void startDocument() throws org.xml.sax.SAXException
startDocument
in interface org.xml.sax.ContentHandler
startDocument
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void endDocument() throws org.xml.sax.SAXException
endDocument
in interface org.xml.sax.ContentHandler
endDocument
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException
processingInstruction
in interface org.xml.sax.ContentHandler
processingInstruction
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXException
startElement
in interface org.xml.sax.ContentHandler
startElement
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
characters
in interface org.xml.sax.ContentHandler
characters
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException
ignorableWhitespace
in interface org.xml.sax.ContentHandler
ignorableWhitespace
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
endElement
in interface org.xml.sax.ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2010 - 2020 Adobe. All Rights Reserved