public class QdParser
extends java.lang.Object
Reader reader = new FileReader(...);
XmlQdParser parser = new XmlQdParser();
parser.parse(handler, reader, false);
for informing handler about XML events in the file represented
by reader and to avoid messages on XML text nodes
(false as last parameter of parse).http://www.koders.com/java),
Holger Eichelberger (adapted to this project)| Modifier and Type | Class and Description |
|---|---|
private static class |
QdParser.Mode
Defines some parsing modes (to be stored into the mode stack, avoids
additional Integer objects).
|
| Modifier and Type | Field and Description |
|---|---|
private HashMap<java.lang.String,java.lang.String> |
attrs
Stores current element attributes.
|
private int |
col
Stores the column position within
line in the document. |
private int |
depth
Depth in nested XML elements.
|
private boolean |
eol
End of line?
|
private java.lang.StringBuilder |
etag
Stores the current end tag name.
|
private int |
line
Stores the line position in the document.
|
private java.lang.String |
lvalue
Stores the left value of an XML attribute.
|
private QdParser.Mode |
mode
Parsing mode.
|
private int |
quotec
Quote char (" or ').
|
private java.lang.String |
rvalue
Stores the right value of an XML attribute.
|
private java.lang.StringBuilder |
sb
Stores the current element being parsed.
|
private Stack<QdParser.Mode> |
st
Parsed elements stack.
|
private java.lang.String |
tagName
Stores the current tag name.
|
| Constructor and Description |
|---|
QdParser() |
| Modifier and Type | Method and Description |
|---|---|
private void |
attributeEquals(int ch)
"=" between attribute name and quoted value.
|
private void |
attributeName(int ch)
Part of the attribute name.
|
private void |
attributeValue(int ch)
Part of the attribute value.
|
private void |
beforeRoot(int ch)
Before parsing the XML root element.
|
private void |
cdataSection(DocHandler doc,
int ch)
Inside a [CDATA] section.
|
private void |
closeTag(DocHandler doc,
int ch)
XML Element closing tag.
|
private void |
comment(int ch)
XML comment.
|
private void |
doctype(int ch)
XML Doctype.
|
private void |
entityRef(int ch)
Reference to an XML Entity.
|
private void |
exc(java.lang.String msg)
Throws an exception with parse location.
|
static void |
main(java.lang.String[] args)
Just testing.
|
private void |
openTag(DocHandler doc,
int ch)
Inside an open tag (XML element started).
|
void |
parse(DocHandler doc,
java.io.InputStream in,
boolean notifyText)
Parse a document.
|
void |
parse(DocHandler doc,
java.io.Reader reader,
boolean notifyText)
Parse a document.
|
private static QdParser.Mode |
popMode(Stack<QdParser.Mode> st)
Pop element from stack.
|
private void |
quotedValue(int ch)
Part of a quoted value.
|
private void |
startTag(int ch)
XML Element start tag.
|
private void |
tagContent(DocHandler doc,
int ch)
Content off an XML element.
|
private void |
textNode(DocHandler doc,
int ch,
boolean notify)
Text node.
|
private Stack<QdParser.Mode> st
private int depth
private QdParser.Mode mode
private int quotec
private int line
private int col
line in the document.private boolean eol
private java.lang.StringBuilder sb
private java.lang.StringBuilder etag
private java.lang.String tagName
private java.lang.String lvalue
private java.lang.String rvalue
private HashMap<java.lang.String,java.lang.String> attrs
private static QdParser.Mode popMode(Stack<QdParser.Mode> st)
st - stackpublic void parse(DocHandler doc, java.io.InputStream in, boolean notifyText) throws QdParserException, java.io.IOException
doc - handler for documentin - the input stream containing the documentnotifyText - notify doc about text nodes at allQdParserException - parse errorjava.io.IOException - in case that reading errors occurpublic void parse(DocHandler doc, java.io.Reader reader, boolean notifyText) throws QdParserException, java.io.IOException
doc - handler for documentreader - input reader containing the documentnotifyText - notify doc about text nodes at allQdParserException - parse errorjava.io.IOException - in case that reading errors occurprivate void tagContent(DocHandler doc, int ch) throws QdParserException
doc - document content handlerch - current charQdParserException - parse errorprivate void attributeEquals(int ch)
throws QdParserException
ch - current charQdParserException - parse errorprivate void attributeName(int ch)
ch - current charprivate void attributeValue(int ch)
throws QdParserException
ch - current charQdParserException - parse errorprivate void quotedValue(int ch)
ch - current charprivate void openTag(DocHandler doc, int ch) throws QdParserException
doc - document content handlerch - current charQdParserException - parse errorprivate void entityRef(int ch)
throws QdParserException
ch - current charQdParserException - parse errorprivate void startTag(int ch)
ch - current charprivate void doctype(int ch)
ch - current charprivate void beforeRoot(int ch)
ch - current charprivate void comment(int ch)
ch - current charprivate void cdataSection(DocHandler doc, int ch) throws QdParserException
doc - document content handlerch - current charQdParserException - parse errorprivate void closeTag(DocHandler doc, int ch) throws QdParserException
doc - document content handlerch - current charQdParserException - parse errorprivate void textNode(DocHandler doc, int ch, boolean notify) throws QdParserException
doc - document content handlerch - current charnotify - notify doc or notQdParserException - parse errorprivate void exc(java.lang.String msg)
throws QdParserException
msg - messageQdParserException - formatted exceptionpublic static void main(java.lang.String[] args)
args - ignored