You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Nicholas Barratt <nb...@akiva.com> on 2002/09/27 21:40:02 UTC
Questions about Pull Parsing (was: Application Driven Parsing)
Does the pull parser return whenever there is no more
available data, or are there instances where it blocks?
Does the pull parser call InputStream.read(), or just
the read(byte []) and read(byte[], int, int) methods,
and if it does, how should the stream indicate that
there are no available bytes (ie, return -1 even though
we aren't at end-of-stream)?
Thanks!
> -----Original Message-----
> From: Andy Clark [mailto:andyc@apache.org]
>
> Unless the implementation has changed, Xerces2 does
> not have to buffer a large chunk of data (or the
> entire document, if the document is small) before
> parsing the content. We had a problem with the
> previous version of Xerces because it would wait
> until it could fill a large buffer (32K? 64K?) or
> until the stream ended before it started parsing
> the document.
>
> However, while the parser can work with whatever
> amount of data is available at that time, you may
> still run into a problem with the Java socket I/O
> stream blocking. I think you could get around this
> by writing a special input stream that checks to
> see how much data is available without blocking
> by calling the "available" method. Then, you would
> only return up to the amount of data available.
> Does this make sense?
>
> NOTE: This assumes that the socket input stream
> implements the "available" method.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Questions about Pull Parsing (was: Application Driven Parsing)
Posted by Andy Clark <an...@apache.org>.
Nicholas Barratt wrote:
> Does the pull parser return whenever there is no more
> available data, or are there instances where it blocks?
The pull interface in XNI exists to allow parser
configurations to state that they can parse docs
in chunks. There is no guarantee that each call to
"parse" means that only one "event" is emitted. With
the pipeline setup, it's impossible to guarantee a
one-to-one correspondence without buffering the
events. Some components in the pipeline could add
or remove events based on the data coming through
the pipeline. Namespace binding is a good example.
Xerces2 implements the XNI pull parser config
interface and stops at "reasonable places" in the
document. If you want to enforce that only one
event is delivered per call to "parse", then you
need to buffer the events. Luckily, this work has
already been done for you in the NekoPull tool.
NekoPull is an actual "pull parsing" API, much
like XMLPULL but it has been designed around XNI.
You don't need to use this API, though.
In the NekoPull package is a buffered XNI pull
parser configuration that can be used with any
XNI parser configuration, whether it implements
XMLPullParserConfiguration or just the XMLParser-
Configuration interface. This buffered config
ensures that one and only one event is delivered
for each call to "parse". You can get the source
code (under an Apache-style license) at the
following URL:
http://www.apache.org/~andyc/neko/
The class you want is BufferedPullConfiguration
found in the org.cyberneko.pull.util package.
> Does the pull parser call InputStream.read(), or just
> the read(byte []) and read(byte[], int, int) methods,
> and if it does, how should the stream indicate that
> there are no available bytes (ie, return -1 even though
> we aren't at end-of-stream)?
The Xerces2 pull parser is not a different impl
than the standard parser. We wrote the Xerces
scanner as a state machine so that it can parse
in chunks. If you use it with SAX, for example,
then it just loops until there is nothing more to
do. But this allows us to provide a way for apps
to have more control over the parsing.
The scanner is actually written to call Reader#read()
and read(char[]) and read(char[],int,int). If an
input stream is provided, then the encoding is auto-
detected and an InputStreamReader is wrapped around
the InputStream using that encoding. This is just
like any other application written to read a char
stream using Reader.
There is no way to embed a -1 or other end-of-stream
indicator. To do this, another protocol would have
to be layered on top. There are some IO classes in
a Sockets-related sample that might be useful for
you. Check out the samples/socket/io/ directory.
--
Andy Clark * andyc@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org