public final class SimpleXMLParser extends Object
The parser can:
<[CDATA[ ... ]]>
construct
\r\n
and \r
to \n
on input, in accordance with the XML Specification, Section 2.11
Modifier and Type | Field and Description |
---|---|
private static int |
ATTRIBUTE_EQUAL |
private static int |
ATTRIBUTE_KEY |
private static int |
ATTRIBUTE_VALUE |
private String |
attributekey
the attribute key.
|
private HashMap<String,String> |
attributes
current attributes
|
private String |
attributevalue
the attribute value.
|
private static int |
CDATA |
private int |
character
The current character.
|
private int |
columns
the column where the current character occurs
|
private SimpleXMLDocHandlerComment |
comment
The handler to which we are going to forward comments.
|
private static int |
COMMENT |
private SimpleXMLDocHandler |
doc
The handler to which we are going to forward document content
|
private StringBuffer |
entity
current entity (whatever is encountered between & and ;)
|
private static int |
ENTITY |
private boolean |
eol
was the last character equivalent to a newline?
|
private static int |
EXAMIN_TAG |
private boolean |
html
Are we parsing HTML?
|
private static int |
IN_CLOSETAG |
private int |
lines
the line we are currently reading
|
private int |
nested
Keeps track of the number of tags that are open.
|
private NewLineHandler |
newLineHandler |
private boolean |
nowhite
A boolean indicating if the next character should be taken into account
if it's a space character.
|
private static int |
PI |
private int |
previousCharacter
The previous character.
|
private static int |
QUOTE |
private int |
quoteCharacter
the quote character that was used to open the quote.
|
private static int |
SINGLE_TAG |
private Stack<Integer> |
stack
the state stack
|
private int |
state
the current state
|
private String |
tag
current tagname
|
private static int |
TAG_ENCOUNTERED |
private static int |
TAG_EXAMINED |
private StringBuffer |
text
current text (whatever is encountered between tags)
|
private static int |
TEXT |
private static int |
UNKNOWN
possible states
|
Modifier | Constructor and Description |
---|---|
private |
SimpleXMLParser(SimpleXMLDocHandler doc,
SimpleXMLDocHandlerComment comment,
boolean html)
Creates a Simple XML parser object.
|
Modifier and Type | Method and Description |
---|---|
private void |
doTag()
Sets the name of the tag.
|
static String |
escapeXML(String s,
boolean onlyASCII)
Deprecated.
moved to
XMLUtil.escapeXML(String, boolean) , left
here for the sake of backwards compatibility |
private void |
flush()
Flushes the text that is currently in the buffer.
|
private static String |
getDeclaredEncoding(String decl) |
private void |
go(Reader r)
Does the actual parsing.
|
private void |
initTag()
Initialized the tag name and attributes.
|
static void |
parse(SimpleXMLDocHandler doc,
InputStream in)
Parses the XML document firing the events to the handler.
|
static void |
parse(SimpleXMLDocHandler doc,
Reader r) |
static void |
parse(SimpleXMLDocHandler doc,
SimpleXMLDocHandlerComment comment,
Reader r,
boolean html)
Parses the XML document firing the events to the handler.
|
private void |
processTag(boolean start)
processes the tag.
|
private int |
restoreState()
Gets a state from the stack
|
private void |
saveState(int s)
Adds a state to the stack.
|
private void |
throwException(String s)
Throws an exception
|
private static final int UNKNOWN
private static final int TEXT
private static final int TAG_ENCOUNTERED
private static final int EXAMIN_TAG
private static final int TAG_EXAMINED
private static final int IN_CLOSETAG
private static final int SINGLE_TAG
private static final int CDATA
private static final int COMMENT
private static final int PI
private static final int ENTITY
private static final int QUOTE
private static final int ATTRIBUTE_KEY
private static final int ATTRIBUTE_EQUAL
private static final int ATTRIBUTE_VALUE
private int character
private int previousCharacter
private int lines
private int columns
private boolean eol
private boolean nowhite
private int state
private final boolean html
private final StringBuffer text
private final StringBuffer entity
private HashMap<String,String> attributes
private final SimpleXMLDocHandler doc
private final SimpleXMLDocHandlerComment comment
private int nested
private int quoteCharacter
private String attributekey
private String attributevalue
private NewLineHandler newLineHandler
private SimpleXMLParser(SimpleXMLDocHandler doc, SimpleXMLDocHandlerComment comment, boolean html)
private void go(Reader r) throws IOException
IOException
private int restoreState()
private void saveState(int s)
s
- a state to add to the stackprivate void flush()
private void initTag()
private void doTag()
private void processTag(boolean start)
start
- if true we are dealing with a tag that has just been opened; if false we are closing a tag.private void throwException(String s) throws IOException
IOException
public static void parse(SimpleXMLDocHandler doc, SimpleXMLDocHandlerComment comment, Reader r, boolean html) throws IOException
doc
- the document handlercomment
- the comment handlerr
- the document. The encoding is already resolved. The reader is not closedhtml
- IOException
- on errorpublic static void parse(SimpleXMLDocHandler doc, InputStream in) throws IOException
doc
- the document handlerin
- the document. The encoding is deduced from the stream. The stream is not closedIOException
- on errorprivate static String getDeclaredEncoding(String decl)
public static void parse(SimpleXMLDocHandler doc, Reader r) throws IOException
doc
- r
- IOException
@Deprecated public static String escapeXML(String s, boolean onlyASCII)
XMLUtil.escapeXML(String, boolean)
, left
here for the sake of backwards compatibilitys
- the string to be escapedonlyASCII
- codes above 127 will always be escaped with &#nn; if
true
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses