Neeraj Bajaj wrote:
> Ok, I again looked into it but its still the same. Can you tell me,
> exactly at what point does parser starts parsing the document ?
hi,
initial state is START_DOCUMENT and parser may do some intial reading
of input when setInput() is called to detect input encoding otherwise only
next*() methods will do parsing.
> Is it at
> xpp.getEventType() ?
getEventType only returns you what is current state (event type)
> Do u check that if parser state is not among defined
> states, set it to START_DOCUMENT and each call to xpp.next() will do
incremental
> parsing.
parser initial state is START_DOCUMENT then after calling it can be in any
number of states with well defined restrictions like END_TAG will match
START_TAG
and eventually parser finishes in END_DOCUMENT final state - in this state
parser will not do any more parsing until you call again setInput() to change
parser state to START_TAG.
i hope that it make it clear how states/vent types works in XmlPull API.
> Or is it xpp.next() that triggers the parsing ?
yes - xpp.next*() triggers parsing to get enough data from input to return
next events.
> Are there other ways to
> trigger the parsing ?
only next*() methods trigger parsing except for initial setInput() that may do
input encoding detection and it requires reading few bytes from input
(as described in XML 1.0 spec).
this makes very easy to use XmlPull API: as there are only two
three of methods:
* setup and configuration: like setInput()
* changing parser state: next*() methods
* state/event inspection: all other methods like getEventType(), getName() etc.
> If you have looked at Xerces samples, take a look at sax.Counter.
> I can parse the same document multiple times. This is what i am trying to do.
did you try to use XmlPullCount that is in src/java/samples?
> > > 2. Second thing, I couldn't use same instance of XMLPullParser to parse
> mulitple
> > > documents. I got following exception
> > >
> > > java.io.EOFException: no more data available
> > > at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:2968)
> > > at org.xmlpull.mxp1.MXParser.more(MXParser.java:2975)
> > > at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1433)
> > > at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1418)
> > > at org.xmlpull.mxp1.MXParser.next(MXParser.java:1137)
> > > at SimpleXmlPullApp.main(SimpleXmlPullApp.java:67)
> >
> > how to reproduce it? do you call setInput for each document?
>
> I think i found the problem. I wasn't creating new InputStream for each parse
:(
that is correct - i will make exception message to be more helpful in MXP1.
> But why there isn't any method that takes String URI as parameter ?
that would require to define exactly what kind of URL should be supported
and as XmlPull API can work on J2ME we do not want to add too much
of requirements into API that would make it difficult to implement it to
work on small devices and limited J2ME API that does not have full
power of J2SE or J2EE to use all kinds of URLs ...
thanks,
alek
--
The ancestor of every action is a thought. - Ralph Waldo Emerson