[jdom-interest] Need help (filters) on SAXHandler ...

Laurent Bihanic laurent.bihanic at atosorigin.com
Fri Mar 8 00:46:31 PST 2002


You may be interested in org.jdom.contrib.input.scanner.ElementScanner (in the 
jdom-contrib module).

ElementScanner is a SAX filter that uses XPath-like expressions to select 
element nodes to build and notifies listeners when these elements becomes 
available during the SAX parse. (Note that this is not real XPath as 
ElementScanner uses regular expressions to match elements in SAXHandler's 
element stack.)

Using it may be as simple as:
    ElementScanner f = new ElementScanner();

    f.addElementListener(listener1, "foo");     // same as "//foo"
    f.addElementListener(listener2, "bar");

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

with listener1 and listener2 instances of your implementation of the 
ElementListener interface.

Hope this helps,


Jon Baer wrote:
> Here is my current problem (after going through the archives and looking
> at FilterList and Filter subject, I realize it hasn't been discussed).
> I am interested in creating a Builder that does not return a JDOM
> Document.  Strange but true.  Basically what I want to do is create an
> Event/Listener with Elements that doesn't really return anything.
> Before I dive in after looking at SAXHandler code I was wondering if
> there was a normal or more easy way of doing this.  I saw that the
> FilterList and Filtering in general mostly pertained to a JDOM Document
> model after it was built. For this reason Im not really interested in
> XPath either..
> The thing is I don't really want to use SAX either because Im really
> after the JDOM Element object for other purposes.
> Does this make sense:
> NullBuilder b = new NullBuilder();
> b.setElementListener("foo", this);
> b.setElementListener("bar", this);
> b.build();
> public void elementReceived(Element e) {
>     if (e.getName().equals("foo")) {}
>     if (e.getName().equals("bar")) {}
> }
> The easiest step in seeming to do this is to rework stack.push(element);
> with some logic in SAXHandler being used.  Correct?  Any ideas?  The
> thing I want to do is simply wrap up the Element once everything has
> been received send it to the listerner, do it's business, and get rid of
> it.
> - Jon
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com


                  wWw    Zzzzz
                 (- -)
Laurent Bihanic           | Tel: +33 (0)1  (Direct line)
Atos Origin               |      +33 (0)1
Intégration - e-Business  | Fax: +33 (0)1
Les Miroirs - Bat. C      |
18, avenue d'Alsace       |
F-92926 La Defense Cedex  | e-Mail: laurent.bihanic at atosorigin.com

"Microsoft isn't the answer. Microsoft is the question and the answer
  is no."

The opinions expressed are entirely my own and may not necessarily be
those of my employer.  Also, I am not now nor have I ever been a
lawyer.  My opinions are provided as-is with absolutely no warrantee of
merchantability or fitness for any particular use.  Besides, you can't
prove I typed this.  No body saw me type this.  Who says I typed this?

More information about the jdom-interest mailing list