[jdom-interest] Consuming elements while parsing

Laurent Bihanic laurent.bihanic at atosorigin.com
Tue Aug 14 08:30:53 PDT 2001


Attached is an XMLFilter that allows an application to consume JDOM elements 
just after they've been built, while the parsing is ongoing.

Applications use it by registering listeners (ElementListener) associated to 
an XPath expression to select the elements they are interested in. Currently, 
the XPath support is trivial and based on the Jakarta RegExp regular 
expression matcher rather than a real XPath engine (maybe the jaxen.org team 
may enhance that ;-) )

  ElementFilter f = new ElementFilter();

  f.addElementListener(new MyImpl(), "x//y");  // All descendants of x named y
  f.addElementListener(new MyImpl(), "y/*/t"); // All grandchilden of y named t

  ElementListener l = new MyImpl2();
  f.addElementListener(l, "/*");               // Root element
  f.addElementListener(l, "z");                // Any node named z

  f.parse(new InputSource("test.xml"));

For more details, see the JavaDoc comments and the example class.

The aim is not to have faster parsing than provided by SAXBuilder but to be 
able to process large documents without loading them in memory, such as log 
files. Of course, if you select only a small subset of the document content, 
the parsing is faster!

Warning: Using this filter requires the "extended" version of SAXHandler 
previously posted and the jakarta-regexp-1.1.jar (available in jdom-contrib\lib).

Feedback wanted !

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ElementFilter.jar
Type: application/x-java-archive
Size: 17730 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20010814/0584ca1f/ElementFilter.bin

More information about the jdom-interest mailing list