Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Shemp: an XMLFilter for use with XOM

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • To: John Cowan <jcowan AT reutershealth.com>, xom-interest AT lists.ibiblio.org (Xom Interest)
  • Cc:
  • Subject: Re: [XOM-interest] Shemp: an XMLFilter for use with XOM
  • Date: Wed, 18 Jun 2003 21:59:22 -0400

The more I think about using NodeFactory as a filter, the more excited I get. This is really neat stuff. I'm still playing with the exact interface, but I think I've pretty much solved the Shemp problem tonight. The key is the following endElement() method in NodeFactory which XOMHandler calls from endElement():

protected void endElement(Element element);

A subclass of NodeFactory can use this as a simple callback to process just that one element. It can invoke any method it needs to invoke on the element to decide whether or not to process it. Then, if the element is no longer needed after processing, the subclass can detach it so it can be garbage collected. This very neatly merges streaming and tree-based processing.

This has been done before (Simon St. Laurent's MOE, Laurent Bihanic's ElementScanner in JDOM) but I don't think I've seen any API make it as simple as XOM makes it. I'm going through the samples now and finding tons of opportunities to use this. This is really powerful stuff, and the real beauty is that if you don't need this you can completely ignore it. Enabling this pattern in XOM only required adding two protected methods (there's an endDocument method as well) and no additional public methods or classes.
--

Elliotte Rusty Harold
elharo AT metalab.unc.edu
Processing XML with Java (Addison-Wesley, 2002)
http://www.cafeconleche.org/books/xmljava
http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA




Archive powered by MHonArc 2.6.24.

Top of Page