|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuxparser.XParser
public class XParser
XParser is a very simple lightweight XML parser. It may be used as a pull parser by iterating through the element and text sections of an XML stream or it may be used to read an entire XML tree into memory as XElems.
XParser works in conjunction with XWriter to support plain text or PKZIP documents. This check happens automatically by sniffing the first few bytes of the input stream. If a zip file is detected, the first zip entry is parsed. Note that when reading from a zip file, no guarantee is made where the stream is positioned once the XML has been read.
Field Summary | |
---|---|
static int |
ELEM_END
Indicates parser currently on element end. |
static int |
ELEM_START
Indicates parser currently on element start. |
static int |
EOF
Indicates end of file (or input stream) |
static int |
TEXT
Indicates parser currently at character data. |
Constructor Summary | |
---|---|
protected |
XParser(java.io.InputStream in)
Private constructor. |
Method Summary | |
---|---|
void |
close()
Close the underlying input stream. |
int |
column()
Get current column number. |
int |
depth()
Get the depth of the current element with the document root being a depth of one. |
XElem |
elem()
Get the current element if type() is ELEM_START or
ELEM_END. |
XElem |
elem(int depth)
Get the at the current depth. |
java.lang.String |
getEncoding()
Get the character encoding of the underlying input stream. |
boolean |
isZipped()
Return if the stream was zipped. |
int |
line()
Get current line number. |
static XParser |
make(java.io.File file)
Make an XParser to parse the specified file. |
static XParser |
make(java.io.InputStream in)
Make an XParser to parse XML from the specified input stream. |
static XParser |
make(java.lang.String xml)
Make an XParser to parse an ASCII string. |
int |
next()
Advance the parser to the next node and return the node type. |
XElem |
parse()
Convenience for parse(true) . |
XElem |
parse(boolean close)
Parse the entire next element into memory as a tree of XElems and optionally close the underlying input stream. |
XElem |
parseCurrent()
Convenience for parseCurrent(false) . |
XElem |
parseCurrent(boolean close)
Parse the entire current element into memory as a tree of XElems and optionally close the underlying input stream. |
void |
skip()
Convenience for skip(depth()) . |
void |
skip(int toDepth)
Skip parses all the content until reaching the end tag of the specified depth. |
XText |
text()
If the current type is TEXT return the XText instance used to store the character data. |
int |
type()
Get the current node type constant which is always the result of the last call to next(). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int EOF
public static final int ELEM_START
public static final int ELEM_END
public static final int TEXT
Constructor Detail |
---|
protected XParser(java.io.InputStream in) throws java.io.IOException
java.io.IOException
Method Detail |
---|
public static XParser make(java.io.File file) throws java.lang.Exception
java.lang.Exception
public static XParser make(java.lang.String xml) throws java.lang.Exception
java.lang.Exception
public static XParser make(java.io.InputStream in) throws java.lang.Exception
java.lang.Exception
public java.lang.String getEncoding() throws java.io.IOException
java.io.IOException
public boolean isZipped() throws java.io.IOException
java.io.IOException
public final XElem parse() throws java.lang.Exception
parse(true)
.
java.lang.Exception
public final XElem parse(boolean close) throws java.lang.Exception
java.lang.Exception
public final XElem parseCurrent() throws java.lang.Exception
parseCurrent(false)
.
java.lang.Exception
public final XElem parseCurrent(boolean close) throws java.lang.Exception
java.lang.Exception
public final int next() throws java.lang.Exception
java.lang.Exception
public void skip() throws java.lang.Exception
skip(depth())
.
java.lang.Exception
public void skip(int toDepth) throws java.lang.Exception
next()
will return the element
or text immediately following the end tag.
java.lang.Exception
public final int type()
public final int depth()
public final XElem elem()
type()
is ELEM_START or
ELEM_END. If type()
is TEXT then this is the parent
element of the current character data. After ELEM_END this XElem
instance is no longer valid and will be reused for further
processing. If depth is zero return null.
public final XElem elem(int depth)
depth()
inclusively. Calling elem(0)
will return the root element and elem(depth()-1)
returns the current element. If depth is invalid, return null.
public final XText text()
next()
this XText instance is no longer valid and will be reused for
further processing. If the current type is not TEXT then
return null.
public final int line()
public final int column()
public final void close()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |