[jdom-interest] Element Scanner

Laurent Bihanic laurent.bihanic at atosorigin.com
Fri May 2 08:18:17 PDT 2003


Robert (Jamie) Munro wrote:

> I've been writing a project that processes XML using ElementScanner.
> Recently, since I updated the CVS, I am getting lots of null pointer
> exceptions. It seems to be because I am doing:
> 
> public void elementMatched(String path, Element e) {
>     // process the element
>     if ([process was successful]) e.detach();
> }
> 
> The idea is that once I have processed the element, I don't need it to stick
> around in memory any more. If it failed to process, I leave it in the JDOM
> tree. The tree that remains at the end of the run is output to a new XML
> file as a log of the process.
> 
> Is this supposed to be legal? Can it be made to work again? It seems a
> pretty logical thing to do, and it certainly used to work. Otherwise, could
> elementMatched return a value to say weather the element should be kept in
> the tree or not?

There's no need to do that as ElementScanner does not build any document. 
Elements are reported to the listeners, not attached to any document, and 
forgotten once all insterested listeners have been called.

Detaching the element is a bad idea because an application can have listeners 
interested in elements at different depths. Detaching a deep element may cause 
other listeners to see partial higher level subtrees.

Yet, I'm interested in seeing the exception stach trace as no NPE should 
happen in any case.

Laurent




More information about the jdom-interest mailing list