|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface for XML event listeners.
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 |
Method Summary | |
void |
attribute(String name,
String value)
Adds an attribute to the current element. |
void |
cdata(String text)
Notification of a CDATA section. |
void |
comment(String text)
Notification of a comment. |
void |
declaration()
Notification of an XML declaration. |
void |
dtd(String name,
String publicID,
String systemID)
Notification of a document type declaration. |
void |
endDocument()
Notification of the end of the document. |
void |
endTag()
Notification of an element end tag. |
XMLEventListenerState |
getState()
Returns the current state of this listener. |
void |
pcdata(char[] ch,
int start,
int length)
Notification of a PCDATA section (as a char array). |
void |
pcdata(String text)
Notification of a PCDATA section (as a String ). |
void |
pi(String target,
String instruction)
Notification of a processing instruction. |
void |
reset()
Resets this XML event listener. |
void |
setState(XMLEventListenerState newState,
String[] newElementStack)
Sets the state of this XML event listener. |
void |
startTag(String type)
Notification of an element start tag. |
void |
whitespace(char[] ch,
int start,
int length)
Notification of ignorable whitespace (as a String ). |
void |
whitespace(String whitespace)
Notification of ignorable whitespace (as a String ). |
Method Detail |
public void reset()
XMLEventListenerStates.UNINITIALIZED
.public void setState(XMLEventListenerState newState, String[] newElementStack) throws IllegalArgumentException
XMLEventListenerStates.UNINITIALIZED
as the state is
equivalent to calling reset()
.newState
- the new state, not null
.newElementStack
- the new element stack, if newState == START_TAG_OPEN
|| newState == WITHIN_ELEMENT
then it should be
non-null
and containing no null
elements,
otherwise it must be null
.newState == null
|| (newState == START_TAG_OPEN && newElementStack == null)
|| (newState == WITHIN_ELEMENT && newElementStack == null)
|| (newState != START_TAG_OPEN && newState != WITHIN_ELEMENT && newElementStack != null)
|| newElementStack[n] == null
(where 0 <= n < newElementStack.length
).public XMLEventListenerState getState()
null
.public void declaration() throws IllegalStateException, IOException
"ISO-8859-1"
, then this
method will produce the following output:
<?xml version="1.0" encoding="ISO-8859-1"?gt;
getState() != BEFORE_XML_DECLARATION
.XMLEventListenerStates.ERROR_STATE
.public void dtd(String name, String publicID, String systemID) throws IllegalStateException, IllegalArgumentException, IOException
-//W3C//DTD XHTML 1.0 Transitional//EN
while the system identifier is:
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
The output is typically similar to this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
or alternatively, if only the system identifier is specified:
<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
name
- the name of the document type, not null
.publicID
- the public identifier, can be null
.systemID
- the system identifier, can be null
, but otherwise
it should be a properly formatted URL, see
section 4.2.2 External Entities
in the XML 1.0 Specification.getState() != BEFORE_XML_DECLARATION &&
getState() != BEFORE_DTD_DECLARATION
.name == null ||
(publicID != null && systemID == null)
.XMLEventListenerStates.ERROR_STATE
.public void startTag(String type) throws IllegalStateException, IllegalArgumentException, IOException
type
- the type of the tag to start, not null
.getState() != BEFORE_XML_DECLARATION &&
getState() != BEFORE_DTD_DECLARATION &&
getState() != BEFORE_ROOT_ELEMENT &&
getState() != START_TAG_OPEN &&
getState() != WITHIN_ELEMENT
.type == null
.XMLEventListenerStates.ERROR_STATE
.public void attribute(String name, String value) throws IllegalStateException, IllegalArgumentException, IOException
name
- the name of the attribute, not null
.value
- the value of the attribute, not null
.getState() != XMLEventListenerStates.START_TAG_OPEN
.name == null || value == null
.XMLEventListenerStates.ERROR_STATE
.public void endTag() throws IllegalStateException, IOException
getState() != START_TAG_OPEN &&
getState() != WITHIN_ELEMENT
XMLEventListenerStates.ERROR_STATE
.public void pcdata(String text) throws IllegalStateException, IllegalArgumentException, IOException
String
).text
- the PCDATA section contents, not null
.getState() != START_TAG_OPEN &&
getState() != WITHIN_ELEMENT
text == null
.XMLEventListenerStates.ERROR_STATE
.public void pcdata(char[] ch, int start, int length) throws IllegalStateException, IllegalArgumentException, IndexOutOfBoundsException, IOException
char
array).ch
- the character array containing the PCDATA section contents, not
null
.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.getState() != START_TAG_OPEN &&
getState() != WITHIN_ELEMENT
ch == null
|| start < 0
|| start >= ch.length
|| length < 0
.start + length > ch.length
.XMLEventListenerStates.ERROR_STATE
.public void whitespace(String whitespace) throws IllegalStateException, IllegalArgumentException, IOException
String
).
Ignorable whitespace can be found anywhere in an XML document,
except above the XML declaration.
This method does not check if the string actually contains
whitespace.
If the state equals XMLEventListenerStates.BEFORE_XML_DECLARATION
, then it will be set to
XMLEventListenerStates.BEFORE_DTD_DECLARATION
, otherwise if the state is
XMLEventListenerStates.START_TAG_OPEN
then it will be set to XMLEventListenerStates.WITHIN_ELEMENT
,
otherwise the state will not be changed.whitespace
- the ignorable whitespace to be written, not null
.getState() == ERROR_STATE
.whitespace == null
.XMLEventListenerStates.ERROR_STATE
.public void whitespace(char[] ch, int start, int length) throws IllegalStateException, IllegalArgumentException, IndexOutOfBoundsException, IOException
String
).
Ignorable whitespace can be found anywhere in an XML document,
except above the XML declaration.
This method does not check if the string actually contains
whitespace.
If the state equals XMLEventListenerStates.BEFORE_XML_DECLARATION
, then it will be set to
XMLEventListenerStates.BEFORE_DTD_DECLARATION
, otherwise if the state is
XMLEventListenerStates.START_TAG_OPEN
then it will be set to XMLEventListenerStates.WITHIN_ELEMENT
,
otherwise the state will not be changed.ch
- the character array containing the text to be written, not
null
.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.getState() == ERROR_STATE
.ch == null
|| start < 0
|| start >= ch.length
|| length < 0
.start + length > ch.length
.XMLEventListenerStates.ERROR_STATE
.public void comment(String text) throws IllegalStateException, IllegalArgumentException, IOException
"--"
.
If the state equals XMLEventListenerStates.BEFORE_XML_DECLARATION
, then it will be set to
XMLEventListenerStates.BEFORE_DTD_DECLARATION
, otherwise if the state is
XMLEventListenerStates.START_TAG_OPEN
then it will be set to XMLEventListenerStates.WITHIN_ELEMENT
,
otherwise the state will not be changed.text
- the text for the comment be written, not null
.getState() == ERROR_STATE
.text == null
.XMLEventListenerStates.ERROR_STATE
.public void pi(String target, String instruction) throws IllegalStateException, IllegalArgumentException, IOException
XMLEventListenerStates.BEFORE_XML_DECLARATION
, then it will be set to
XMLEventListenerStates.BEFORE_DTD_DECLARATION
, otherwise the state will not be
changed.target
- an identification of the application at which the instruction is
targeted, not null
.instruction
- the instruction, can be null
, which is equivalent to an
empty string.getState() == ERROR_STATE
.target == null
.XMLEventListenerStates.ERROR_STATE
.public void cdata(String text) throws IllegalStateException, IllegalArgumentException, IOException
"]]>"
. 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.text
- the contents of the CDATA section, not null
.getState() != START_TAG_OPEN &&
getState() != WITHIN_ELEMENT
text == null
.XMLEventListenerStates.ERROR_STATE
.public void endDocument() throws IllegalStateException, IOException
reset()
is called.getState() == UNINITIALIZED
|| getState() == DOCUMENT_ENDED
.XMLEventListenerStates.ERROR_STATE
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |