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(OutputStream stream)
Creates an XML serializer that writes the serialized XML stream
to the given output stream using the UTF-8 character encoding.
|
ToXmlContentHandler(OutputStream stream,
String encoding)
Creates an XML serializer that writes the serialized XML stream
to the given output stream using the given character encoding.
|
ToXmlContentHandler(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(String namespaceURI,
String localName,
String qName)
Outputs the specified end tag.
|
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Escapes and outputs the given characters.
|
void |
processingInstruction(String target,
String data)
Serializes a processing instruction.
|
void |
startDocument()
Starts the XML serialization by outputting the <?xml?> header.
|
void |
startElement(String namespaceURI,
String localName,
String qName,
Attributes atts)
Outputs the specified start tag with the given attributes.
|
String |
toString()
Returns the serialized XML document (assuming the default no-argument
constructor was used).
|
endPrefixMapping, error, fatalError, notationDecl, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warningpublic ToXmlContentHandler(OutputStream stream, String encoding) throws UnsupportedEncodingException
stream - XML output streamencoding - character encodingUnsupportedEncodingException - if the encoding is not supportedpublic ToXmlContentHandler(OutputStream stream)
stream - XML output streampublic ToXmlContentHandler(Writer writer)
writer - XML output streampublic ToXmlContentHandler()
toString() method to access
the serialized XML document.public void startDocument()
throws SAXException
startDocument in interface ContentHandlerstartDocument in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void endDocument()
throws SAXException
endDocument in interface ContentHandlerendDocument in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void processingInstruction(String target, String data) throws SAXException
processingInstruction in interface ContentHandlerprocessingInstruction in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
startElement in interface ContentHandlerstartElement in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void characters(char[] ch,
int start,
int length)
throws SAXException
characters in interface ContentHandlercharacters in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void ignorableWhitespace(char[] ch,
int start,
int length)
throws SAXException
ignorableWhitespace in interface ContentHandlerignorableWhitespace in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void endElement(String namespaceURI, String localName, String qName) throws SAXException
endElement in interface ContentHandlerendElement in class org.xml.sax.helpers.DefaultHandlerSAXExceptionCopyright © 2004-2020 The Apache Software Foundation. All Rights Reserved.