[jdom-interest] process on the fly

Laurent Bihanic laurent.bihanic at atosorigin.com
Tue Sep 25 05:04:00 PDT 2001


Hi,

The only way to get parsed data on the fly from an XML parser is to use the 
SAX API. JDOM provides SAXBuilder that use this API but can only return a 
whole JDOM document and hence waits until the parsing is complete to do so.

To process XML data while they are being parsed, you should either use SAX 
directly or create a sub-class of SAXHandler that gives you access to the JDOM 
Elements while they are being built, either on startElement() (Element + 
Attributes but no children) or endElement() (Element + whole subtree).

I had the same need on a past project and I developed an XML Filter that goes 
a little bit beyond that by allowing you to select the Elements you are 
interested in (using XPath expressions) and by not attaching the Elements to 
any Document so that they can be garbage-collected as soon as the application 
is done with them.
I posted this development to this list about a month ago but so far I got no 
feedback. Interested?

Laurent

jc c wrote:

> hi, as one of the benifit as stated in JDOM, it allows
> take in inputstream as input, one thing i don't
>  understand is that if i want to take in a xml file
>  that is over the network and is slowly streaming in,
>  can JDOM handle this kind of input?? because this
> will
>  introduce that the file may not be complete and still
>  waiting the file to be complete.  In this case is
> JDOM
>  waits for the complete file to parse or parse on the
>  fly???? can you give a example on how to handle a
> file
>  on the fly ( as reading xml file)???? in the notes i
>  can't find any examples...i really hope that you can
>  help, thanks a million.





More information about the jdom-interest mailing list