Package org.znerd.xmlenc
Class XMLOutputter
- java.lang.Object
-
- org.znerd.xmlenc.XMLOutputter
-
- All Implemented Interfaces:
StatefulXMLEventListener,XMLEventListener,XMLEventListenerStates
public class XMLOutputter extends java.lang.Object implements StatefulXMLEventListener
Stream-based XML outputter. Instances of this class are able to write XML output toWriters.Standards compliance
This class is intended to produce output that conforms to the XML 1.0 Specification. However, not all applicable restrictions are validated. For example, it is currently not checked if names contain characters that are invalid within a Name production. Furthermore, not all possible XML documents can be produced. The following limitations apply:- The name of the applicable encoding is always printed in the XML declaration, even though it may not be necessary.
- The
standaloneattribute is not supported in the XML declaration. - Internal DTD subsets are not supported.
- Spacing is fixed, whitespace is always kept to the minimum.
Supported encodings
The following encodings are supported:- UTF-8
- UTF-16
- ISO-10646-UCS-2
- ISO-10646-UCS-4
- ISO-10646-UTF-1
- US-ASCII (also known as ASCII)
- ISO-8859-n, where n is the part number
Multi-threading
This class is not thread-safe.Exceptions
Note that all methods check the state first and then check the arguments. This means that if the state is incorrect and the arguments are incorrect, then anIllegalStateExceptionwill be thrown. If any of the writing methods generates anIOException, then the state will be set toXMLEventListenerStates.ERROR_STATEand no more output can be performed.Performance hints
It is usually a good idea to letXMLOutputterinstances write to bufferedWriters. This typically improves performance on large documents or relatively slow or blocking output streams. Instances of this class can be cached in a pool to reduce object creations. Callreset()(with no arguments) when storing an instance in the pool. Usereset(Writer,String)(with 2 arguments) to re-initialize the instance after fetching it from the pool.- Since:
- xmlenc 0.19
- Version:
- $Revision: 1.118 $ $Date: 2005/09/12 08:40:02 $
- Author:
- Ernst de Haan (wfe.dehaan@gmail.com), Jochen Schwoerer (j.schwoerer [at] web.de)
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_INDENTATIONDefault indentation.-
Fields inherited from interface org.znerd.xmlenc.XMLEventListenerStates
AFTER_ROOT_ELEMENT, BEFORE_DTD_DECLARATION, BEFORE_ROOT_ELEMENT, BEFORE_XML_DECLARATION, DOCUMENT_ENDED, ERROR_STATE, START_TAG_OPEN, UNINITIALIZED, WITHIN_ELEMENT
-
-
Constructor Summary
Constructors Constructor Description XMLOutputter()Constructs a newXMLOutputter.XMLOutputter(java.io.Writer out, java.lang.String encoding)Constructs a newXMLOutputterfor the specifiedWriterand encoding.XMLOutputter(java.io.Writer out, XMLEncoder encoder)Constructs a newXMLOutputterfor the specifiedWriterandencoder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidattribute(java.lang.String name, java.lang.String value)Adds an attribute to the current element.voidcdata(java.lang.String text)Writes a CDATA section.voidclose()Closes all open elements.voidcomment(java.lang.String text)Writes the specified comment.voiddeclaration()Writes the XML declaration.voiddtd(java.lang.String name, java.lang.String publicID, java.lang.String systemID)Writes a document type declaration.voidendDocument()Ends the XML output.voidendTag()Writes an element end tag.java.lang.String[]getElementStack()Returns a copy of the element stack.intgetElementStackCapacity()Returns the current capacity for the stack of open elements.intgetElementStackSize()Returns the current depth of open elements.java.lang.StringgetEncoding()Returns the encoding of this outputter.java.lang.StringgetIndentation()Returns the string currently used for indentation.LineBreakgetLineBreak()Returns the currently used line break.chargetQuotationMark()Gets the quotation mark character.XMLEventListenerStategetState()Returns the current state of this outputter.java.io.WritergetWriter()Returns the output stream this outputter uses.booleanisEscaping()Checks if escaping is currently enabled.voidpcdata(char[] ch, int start, int length)Writes the specified character array as PCDATA.voidpcdata(java.lang.String text)Writes the specifiedStringas PCDATA.voidpi(java.lang.String target, java.lang.String instruction)Writes a processing instruction.voidreset()Resets thisXMLOutputter.voidreset(java.io.Writer out, java.lang.String encoding)Resets thisXMLOutputterand configures it for the specified output stream and encoding.voidreset(java.io.Writer out, XMLEncoder encoder)Resets thisXMLOutputterand configures it for the specified output stream and encoder.voidsetElementStackCapacity(int newCapacity)Sets the capacity for the stack of open elements.voidsetEscaping(boolean escapeAmpersands)Sets if ampersands should be escaped.voidsetIndentation(java.lang.String indentation)Sets the string to be used for indentation.voidsetLineBreak(LineBreak lineBreak)Sets the type of line break to use.voidsetQuotationMark(char c)Sets the quotation mark character to use.voidsetState(XMLEventListenerState newState, java.lang.String[] newElementStack)Sets the state of this outputter.voidstartTag(java.lang.String type)Writes an element start tag.voidwhitespace(char[] ch, int start, int length)Writes text from the specified character array as ignorable whitespace.voidwhitespace(java.lang.String whitespace)Writes the specified ignorable whitespace.
-
-
-
Field Detail
-
DEFAULT_INDENTATION
public static final java.lang.String DEFAULT_INDENTATION
Default indentation. This is the empty string,"", since by default no indentation is performed.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XMLOutputter
public XMLOutputter()
Constructs a newXMLOutputter. This sets the state toXMLEventListenerStates.UNINITIALIZED.
-
XMLOutputter
public XMLOutputter(java.io.Writer out, java.lang.String encoding) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, java.io.UnsupportedEncodingExceptionConstructs a newXMLOutputterfor the specifiedWriterand encoding. This sets the state toXMLEventListenerStates.BEFORE_XML_DECLARATION. The encoding will be stored exactly as passed, leaving the case intact.- Parameters:
out- the output stream to write to, notnull.encoding- the encoding, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() !=.XMLEventListenerStates.UNINITIALIZED&& getState() !=XMLEventListenerStates.AFTER_ROOT_ELEMENT&& getState() !=XMLEventListenerStates.ERROR_STATEjava.lang.IllegalArgumentException- ifout == null || encoding == null.java.io.UnsupportedEncodingException- if the specified encoding is not supported.
-
XMLOutputter
public XMLOutputter(java.io.Writer out, XMLEncoder encoder) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, java.io.UnsupportedEncodingExceptionConstructs a newXMLOutputterfor the specifiedWriterandencoder. This sets the state toXMLEventListenerStates.BEFORE_XML_DECLARATION.- Parameters:
out- the output stream to write to, notnull.encoder- the encoder, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() !=.XMLEventListenerStates.UNINITIALIZED&& getState() !=XMLEventListenerStates.AFTER_ROOT_ELEMENT&& getState() !=XMLEventListenerStates.ERROR_STATEjava.lang.IllegalArgumentException- ifout == null || encoder == null.java.io.UnsupportedEncodingException- if the specified encoding is not supported.
-
-
Method Detail
-
getWriter
public final java.io.Writer getWriter()
Returns the output stream this outputter uses.- Returns:
- the output stream of this encoding, only
nullif and only if the state isXMLEventListenerStates.UNINITIALIZED.
-
getEncoding
public final java.lang.String getEncoding()
Returns the encoding of this outputter.- Returns:
- the encoding used by this outputter, only
nullif and only if the state isXMLEventListenerStates.UNINITIALIZED.
-
reset
public void reset()
Resets thisXMLOutputter. TheWriterand the encoding will be set tonull, the element stack will be cleared, the state will be set toXMLEventListenerStates.UNINITIALIZED, the line break will be set toLineBreak.NONEand the indentation will be set toDEFAULT_INDENTATION(an empty string).- Specified by:
resetin interfaceXMLEventListener
-
reset
public final void reset(java.io.Writer out, java.lang.String encoding) throws java.lang.IllegalArgumentException, java.io.UnsupportedEncodingExceptionResets thisXMLOutputterand configures it for the specified output stream and encoding. This resets the state toXMLEventListenerStates.BEFORE_XML_DECLARATIONand clears the stack of open elements.- Parameters:
out- the output stream to write to, notnull.encoding- the encoding, notnull.- Throws:
java.lang.IllegalArgumentException- ifout == null || encoding == null.java.io.UnsupportedEncodingException- if the specified encoding is not supported.
-
reset
public final void reset(java.io.Writer out, XMLEncoder encoder) throws java.lang.IllegalArgumentException, java.io.UnsupportedEncodingExceptionResets thisXMLOutputterand configures it for the specified output stream and encoder. This resets the state toXMLEventListenerStates.BEFORE_XML_DECLARATIONand clears the stack of open elements.- Parameters:
out- the output stream to write to, notnull.encoder- the encoder, notnull.- Throws:
java.lang.IllegalArgumentException- ifout == null || encoder == null.java.io.UnsupportedEncodingException- if the specified encoding is not supported.
-
setState
public final void setState(XMLEventListenerState newState, java.lang.String[] newElementStack) throws java.lang.IllegalArgumentException
Sets the state of this outputter. Normally, it is not necessary to call this method. Calling this method withXMLEventListenerStates.UNINITIALIZEDas the state is equivalent to callingreset(). Caution: This method can be used to let this class generate invalid XML.- Specified by:
setStatein interfaceXMLEventListener- Parameters:
newState- the new state, notnull.newElementStack- the new element stack, ifnewState == START_TAG_OPEN || newState == WITHIN_ELEMENTthen it should be non-nulland containing nonullelements, otherwise it must benull.- Throws:
java.lang.IllegalArgumentException- ifnewState == null || (newState ==(whereXMLEventListenerStates.START_TAG_OPEN&& newElementStack == null) || (newState ==XMLEventListenerStates.WITHIN_ELEMENT&& newElementStack == null) || (newState !=XMLEventListenerStates.START_TAG_OPEN&& newState !=XMLEventListenerStates.WITHIN_ELEMENT&& newElementStack != null) || newElementStack[n] == null0 <= n < newElementStack.length).- Since:
- xmlenc 0.22
-
getState
public final XMLEventListenerState getState()
Returns the current state of this outputter.- Specified by:
getStatein interfaceStatefulXMLEventListener- Specified by:
getStatein interfaceXMLEventListener- Returns:
- the current state, cannot be
null.
-
isEscaping
public final boolean isEscaping()
Checks if escaping is currently enabled. If escaping is enabled, then all ampersand characters ('&') are replaced by the character entity reference"&". This affects PCDATA string printing (pcdata(String)andpcdata(char[],int,int)) and attribute value printing (attribute(String,String)).- Returns:
trueif escaping is enabled,falseotherwise.
-
setEscaping
public final void setEscaping(boolean escapeAmpersands)
Sets if ampersands should be escaped. This affects PCDATA string printing (pcdata(String)andpcdata(char[],int,int)) and attribute value printing (attribute(String,String)). If ampersands are not escaped, then entity references can be printed.- Parameters:
escapeAmpersands-trueif ampersands should be escaped,falseotherwise.- Since:
- xmlenc 0.24
-
getElementStack
public final java.lang.String[] getElementStack()
Returns a copy of the element stack. The returned array will be a new array. The size of the array will be equal to the element stack size (seegetElementStackSize().- Returns:
- a newly constructed array that contains all the element types
currently on the element stack, or
nullif there are no elements on the stack. - Since:
- xmlenc 0.22
-
getElementStackSize
public final int getElementStackSize()
Returns the current depth of open elements.- Returns:
- the open element depth, always >= 0.
- Since:
- xmlenc 0.22
-
getElementStackCapacity
public final int getElementStackCapacity()
Returns the current capacity for the stack of open elements.- Returns:
- the open element stack capacity, always >=
getElementStackSize(). - Since:
- xmlenc 0.28
-
setElementStackCapacity
public final void setElementStackCapacity(int newCapacity) throws java.lang.IllegalArgumentException, java.lang.OutOfMemoryErrorSets the capacity for the stack of open elements. The new capacity must at least allow the stack to contain the current open elements.- Parameters:
newCapacity- the new capacity, >=getElementStackSize().- Throws:
java.lang.IllegalArgumentException- ifnewCapacity <.getElementStackSize()java.lang.OutOfMemoryError- if a new array cannot be allocated; this object will still be usable, but the capacity will remain unchanged.
-
setQuotationMark
public final void setQuotationMark(char c) throws java.lang.IllegalArgumentExceptionSets the quotation mark character to use. This character is printed before and after an attribute value. It can be either the single or the double quote character. The default quotation mark character is'"'.- Parameters:
c- the character to put around attribute values, either'\''or'"'.- Throws:
java.lang.IllegalArgumentException- ifc != '\'' && c != '"'.
-
getQuotationMark
public final char getQuotationMark()
Gets the quotation mark character. This character is used to mark the start and end of an attribute value. The default quotation mark character is'"'.- Returns:
- the character to put around attribute values, either
'\''or'"'.
-
setLineBreak
public final void setLineBreak(LineBreak lineBreak)
Sets the type of line break to use. If the line break is set toLineBreak.NONE, then the indentation is reset to an empty string.- Parameters:
lineBreak- the line break to use; specifyingnullas the argument is equivalent to specifyingLineBreak.NONE.
-
getLineBreak
public final LineBreak getLineBreak()
Returns the currently used line break.- Returns:
- the currently used line break, never
null.
-
setIndentation
public final void setIndentation(java.lang.String indentation) throws java.lang.IllegalStateExceptionSets the string to be used for indentation. A line break must be set prior to calling this method.Only space and tab characters are allowed for the indentation.
- Parameters:
indentation- the character string used for indentation, ornullifthe default indentationshould be used.- Throws:
java.lang.IllegalStateException- if.getLineBreak()== LineBreak.NONEjava.lang.IllegalArgumentException- ifindentationcontains characters that are neither a space nor a tab.
-
getIndentation
public final java.lang.String getIndentation()
Returns the string currently used for indentation.- Returns:
- the character string used for indentation, never
null.
-
declaration
public final void declaration() throws java.lang.IllegalStateException, java.io.IOExceptionWrites the XML declaration. This method always prints the name of the encoding. The case of the encoding is as it was specified during initialization (or re-initialization). If the encoding is set to"ISO-8859-1", then this method will produce the following output:<?xml version="1.0" encoding="ISO-8859-1"?>- Specified by:
declarationin interfaceXMLEventListener- Throws:
java.lang.IllegalStateException- ifgetState() !=.XMLEventListenerStates.BEFORE_XML_DECLARATIONjava.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
dtd
public final void dtd(java.lang.String name, java.lang.String publicID, java.lang.String systemID) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, InvalidXMLException, java.io.IOExceptionWrites a document type declaration. An external subset can be specified using either a system identifier (alone), or using both a public identifier and a system identifier. It can never be specified using a public identifier alone. For example, for XHTML 1.0 the public identifier is:
while the system identifier is:-//W3C//DTD XHTML 1.0 Transitional//EN
The output is typically similar to this:http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
or alternatively, if only the system identifier is specified:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">- Specified by:
dtdin interfaceXMLEventListener- Parameters:
name- the name of the document type, notnull.publicID- the public identifier, can benull, but if not, then it must match the PubidLiteral production in the XML 1.0 Specification, when quoted.systemID- the system identifier, can benull, but if not, then it must match the SystemLiteral production in the XML 1.0 Specification, when quoted.- Throws:
java.lang.IllegalStateException- ifgetState() !=.XMLEventListenerStates.BEFORE_XML_DECLARATION&& getState() !=XMLEventListenerStates.BEFORE_DTD_DECLARATIONjava.lang.IllegalArgumentException- ifname == null || (publicID != null && systemID == null).InvalidXMLException- if the specified name does not match the Name production (seeXMLChecker.checkName(String)).java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
startTag
public final void startTag(java.lang.String type) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, java.io.IOExceptionWrites an element start tag. The element type name will be stored in the internal element stack. If necessary, the capacity of this stack will be extended.- Specified by:
startTagin interfaceXMLEventListener- Parameters:
type- the type of the tag to start, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() !=.XMLEventListenerStates.BEFORE_XML_DECLARATION&& getState() !=XMLEventListenerStates.BEFORE_DTD_DECLARATION&& getState() !=XMLEventListenerStates.BEFORE_ROOT_ELEMENT&& getState() !=XMLEventListenerStates.START_TAG_OPEN&& getState() !=XMLEventListenerStates.WITHIN_ELEMENTjava.lang.IllegalArgumentException- iftype == null.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
attribute
public final void attribute(java.lang.String name, java.lang.String value) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, java.io.IOExceptionAdds an attribute to the current element. There must currently be an open element. The attribute value is surrounded by single quotes.- Specified by:
attributein interfaceXMLEventListener- Parameters:
name- the name of the attribute, notnull.value- the value of the attribute, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() !=.XMLEventListenerStates.START_TAG_OPENjava.lang.IllegalArgumentException- ifname == null || value == null.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
endTag
public final void endTag() throws java.lang.IllegalStateException, java.io.IOExceptionWrites an element end tag.- Specified by:
endTagin interfaceXMLEventListener- Throws:
java.lang.IllegalStateException- ifgetState() !=XMLEventListenerStates.START_TAG_OPEN&& getState() !=XMLEventListenerStates.WITHIN_ELEMENTjava.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
pcdata
public final void pcdata(java.lang.String text) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, InvalidXMLException, java.io.IOExceptionWrites the specifiedStringas PCDATA.- Specified by:
pcdatain interfaceXMLEventListener- Parameters:
text- the PCDATA text to be written, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() !=XMLEventListenerStates.START_TAG_OPEN&& getState() !=XMLEventListenerStates.WITHIN_ELEMENTjava.lang.IllegalArgumentException- iftext == null.InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
pcdata
public final void pcdata(char[] ch, int start, int length) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException, InvalidXMLException, java.io.IOExceptionWrites the specified character array as PCDATA.- Specified by:
pcdatain interfaceXMLEventListener- Parameters:
ch- the character array containing the text to be written, notnull.start- the start index in the array, must be >= 0 and it must be <ch.length.length- the number of characters to read from the array, must be > 0.- Throws:
java.lang.IllegalStateException- ifgetState() !=XMLEventListenerStates.START_TAG_OPEN&& getState() !=XMLEventListenerStates.WITHIN_ELEMENTjava.lang.IllegalArgumentException- ifch == null || start < 0 || start >= ch.length || length < 0.java.lang.IndexOutOfBoundsException- ifstart + length > ch.length.InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
whitespace
public final void whitespace(java.lang.String whitespace) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, InvalidXMLException, java.io.IOExceptionWrites the specified ignorable whitespace. Ignorable whitespace may be written anywhere in XML output stream, except above the XML declaration. If the state equalsXMLEventListenerStates.BEFORE_XML_DECLARATION, then it will be set toXMLEventListenerStates.BEFORE_DTD_DECLARATION, otherwise if the state isXMLEventListenerStates.START_TAG_OPENthen it will be set toXMLEventListenerStates.WITHIN_ELEMENT, otherwise the state will not be changed.- Specified by:
whitespacein interfaceXMLEventListener- Parameters:
whitespace- the ignorable whitespace to be written, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() !=.XMLEventListenerStates.BEFORE_XML_DECLARATION&& getState() !=XMLEventListenerStates.BEFORE_DTD_DECLARATION&& getState() !=XMLEventListenerStates.BEFORE_ROOT_ELEMENT&& getState() !=XMLEventListenerStates.START_TAG_OPEN&& getState() !=XMLEventListenerStates.WITHIN_ELEMENT&& getState() !=XMLEventListenerStates.AFTER_ROOT_ELEMENTjava.lang.IllegalArgumentException- ifwhitespace == null.InvalidXMLException- if the specified character string contains a character that is invalid as whitespace.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
whitespace
public final void whitespace(char[] ch, int start, int length) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException, InvalidXMLException, java.io.IOExceptionWrites text from the specified character array as ignorable whitespace. Ignorable whitespace may be written anywhere in XML output stream, except above the XML declaration. This method does not check if the string actually contains whitespace. If the state equalsXMLEventListenerStates.BEFORE_XML_DECLARATION, then it will be set toXMLEventListenerStates.BEFORE_DTD_DECLARATION, otherwise if the state isXMLEventListenerStates.START_TAG_OPENthen it will be set toXMLEventListenerStates.WITHIN_ELEMENT, otherwise the state will not be changed.- Specified by:
whitespacein interfaceXMLEventListener- Parameters:
ch- the character array containing the text to be written, notnull.start- the start index in the array, must be >= 0 and it must be <ch.length.length- the number of characters to read from the array, must be > 0.- Throws:
java.lang.IllegalStateException- ifgetState() !=.XMLEventListenerStates.BEFORE_XML_DECLARATION&& getState() !=XMLEventListenerStates.BEFORE_DTD_DECLARATION&& getState() !=XMLEventListenerStates.BEFORE_ROOT_ELEMENT&& getState() !=XMLEventListenerStates.START_TAG_OPEN&& getState() !=XMLEventListenerStates.WITHIN_ELEMENT&& getState() !=XMLEventListenerStates.AFTER_ROOT_ELEMENTjava.lang.IllegalArgumentException- ifch == null || start < 0 || start >= ch.length || length < 0.java.lang.IndexOutOfBoundsException- ifstart + length > ch.length.InvalidXMLException- if the specified character string contains a character that is invalid as whitespace.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
comment
public final void comment(java.lang.String text) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, InvalidXMLException, java.io.IOExceptionWrites the specified comment. The comment should not contain the string"--". If the state equalsXMLEventListenerStates.BEFORE_XML_DECLARATION, then it will be set toXMLEventListenerStates.BEFORE_DTD_DECLARATION, otherwise if the state isXMLEventListenerStates.START_TAG_OPENthen it will be set toXMLEventListenerStates.WITHIN_ELEMENT, otherwise the state will not be changed.- Specified by:
commentin interfaceXMLEventListener- Parameters:
text- the text for the comment be written, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() !=.XMLEventListenerStates.BEFORE_XML_DECLARATION&& getState() !=XMLEventListenerStates.BEFORE_DTD_DECLARATION&& getState() !=XMLEventListenerStates.BEFORE_ROOT_ELEMENT&& getState() !=XMLEventListenerStates.START_TAG_OPEN&& getState() !=XMLEventListenerStates.WITHIN_ELEMENT&& getState() !=XMLEventListenerStates.AFTER_ROOT_ELEMENTjava.lang.IllegalArgumentException- iftext == null.InvalidXMLException- if the specified text contains an invalid character.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
pi
public final void pi(java.lang.String target, java.lang.String instruction) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, java.io.IOExceptionWrites a processing instruction. A target and an optional instruction should be specified. A processing instruction can appear above and below the root element, and between elements. It cannot appear inside an element start or end tag, nor inside a comment. Processing instructions cannot be nested. If the state equalsXMLEventListenerStates.BEFORE_XML_DECLARATION, then it will be set toXMLEventListenerStates.BEFORE_DTD_DECLARATION, otherwise the state will not be changed.- Specified by:
piin interfaceXMLEventListener- Parameters:
target- an identification of the application at which the instruction is targeted, notnull.instruction- the instruction, can benull, which is equivalent to an empty string.- Throws:
java.lang.IllegalStateException- ifgetState() !=.XMLEventListenerStates.BEFORE_XML_DECLARATION&& getState() !=XMLEventListenerStates.BEFORE_DTD_DECLARATION&& getState() !=XMLEventListenerStates.BEFORE_ROOT_ELEMENT&& getState() !=XMLEventListenerStates.START_TAG_OPEN&& getState() !=XMLEventListenerStates.WITHIN_ELEMENT&& getState() !=XMLEventListenerStates.AFTER_ROOT_ELEMENTjava.lang.IllegalArgumentException- iftarget == null.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
cdata
public final void cdata(java.lang.String text) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, java.io.IOExceptionWrites a CDATA section. A CDATA section can contain any string, except"]]>". This will, however, not be checked by this method. Left angle brackets and ampersands will be output in their literal form; they need not (and cannot) be escaped using"<"and"&". If the specified string is empty (i.e."".equals(text), then nothing will be output. If the specified string contains characters that cannot be printed in this encoding, then the result is undefined.- Specified by:
cdatain interfaceXMLEventListener- Parameters:
text- the contents of the CDATA section, notnull.- Throws:
java.lang.IllegalStateException- ifgetState() !=XMLEventListenerStates.START_TAG_OPEN&& getState() !=XMLEventListenerStates.WITHIN_ELEMENTjava.lang.IllegalArgumentException- iftext == null.java.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
close
public final void close() throws java.lang.IllegalStateException, java.io.IOExceptionCloses all open elements. After calling this method, only thewhitespace(String)method can be called. If you would like to flush the output stream as well, callendDocument()instead.- Throws:
java.lang.IllegalStateException- ifgetState() !=XMLEventListenerStates.START_TAG_OPEN&& getState() !=XMLEventListenerStates.WITHIN_ELEMENT&& getState() !=XMLEventListenerStates.AFTER_ROOT_ELEMENTjava.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
endDocument
public final void endDocument() throws java.lang.IllegalStateException, java.io.IOExceptionEnds the XML output. All open elements will be closed and the underlying output stream will be flushed usinggetWriter().flush(). After calling this method, no more output can be written until this outputter is reset.- Specified by:
endDocumentin interfaceXMLEventListener- Throws:
java.lang.IllegalStateException- ifgetState() !=.XMLEventListenerStates.START_TAG_OPEN&& getState() !=XMLEventListenerStates.WITHIN_ELEMENT&& getState() !=XMLEventListenerStates.AFTER_ROOT_ELEMENTjava.io.IOException- if an I/O error occurs; this will set the state toXMLEventListenerStates.ERROR_STATE.
-
-