[jdom-interest] Re: Proposal: JDOM event based processing

James Strachan james at metastuff.com
Tue Nov 7 02:49:49 PST 2000

From: "Patrick Dowler" <Patrick.Dowler at nrc.ca>
> Umm, isn't the whole point of JDOM to have an object model rather than an
> event stream?

Yes.  All I'm saying is often you only need part of the document tree to be
in memory to be able to process it correctly. Think ASCII files - we're used
to processing a 'buffer' at a time aren't we? We rarely ever make the
assumption we can fit it all in RAM at once do we? Surely we can do the same
with JDOM too? The XML document can often be too big to fit all into RAM at

> If you want events, wouldn't you use SAX directly?

SAX is too low level for non trivial use. SAX is sub-Element level
granularity, we have to build the Elements ourselves from SAX events and
then connect them up by hand into Element subtrees.

JDOM right now is Document level granularity - we get a whole Document or
nothing if it wont fit in RAM.

This proposal is to allow a 'SAXProcessor' to create document sub trees and
process those - i.e sub-Document (i.e. Element tree) level.

> The thing described below could be implemented as an event handler (using
> SAX) or as a tree-walker (using JDOM). You SAXProcessor coudl just as
> easily be a JDOMWalker, yes?
>         Document doc = ...

You missed out the vital step. The "..." could have just tried to load a 1Gb
XML file into RAM and barfed because it wouldn't fit. Or for a big XML file
that would just fit, it would have sat there on high CPU usage for a long
time until it had read the entire tree into memory.

Allowing sub-document level events (Element sub tree) processing would mean
processing could occur during the parse not after. Also we should be able to
process any size of XML document provided our sub-tree is of reasonable
size, just like in the ASCII world when we try to choose an adequately sized
'buffer' for processing..

>         JDOMWalker walker = new JDOMWalker();
>         walker.addProcessor( "book", new BookHandler() );
>         walker.walk( doc );


James Strachan
email: james at metastuff.com
web: http://www.metastuff.com

If you are not the addressee of this confidential e-mail and any
attachments, please delete it and inform the sender; unauthorised
redistribution or publication is prohibited. Views expressed are those of
the author and do not necessarily represent those of Citria Limited.

More information about the jdom-interest mailing list