[jdom-interest] [Fwd: JDOM ?]

Dennis Sosnoski dms at sosnoski.com
Mon Mar 11 18:07:49 PST 2002


You can subclass SAXBuilder and override the createParser method to only 
create a parser the first time through. That's probably the simplest 
solution to get reusability (though I haven't looked into whether there 
might be other issues).

It seems like this is a reasonable thing for SAXBuilder to do by 
default, though. Is there any reason you'd want the code to always build 
a new parser? I can't think of any.

  - Dennis

Jason Hunter wrote:

>Please include Kim on any replies.
>
>-jh-
>
>
> ------------------------------------------------------------------------
>
> Subject:
>
> JDOM ?
> From:
>
> "K.Gillies" <kgillies at gemini.edu>
> Date:
>
> Mon, 11 Mar 2002 16:28:14 -0700
> To:
>
> jhunter at acm.org
>
>
> Hi Jason,
>   I apologize for writing you directly.  I'm not a regular watcher of 
> the JDOM
> lists although I'm use JDOM -- and I like it!  So if you like, please 
> give me
> advice.
>
>   I have an application that reads many XML files that must be 
> validated to
> several DTDs.  Someone suggested that creating XML parsers and 
> configuring
> every time a new file must be parsed was rather expensive and that 
> parsers
> should be cached like JDBC connections are often cached.  A new parser
> isn't needed for every document.  I didn't do any measurements since
> it seemed like a reasonable statement.
>
>   So I built a class to provide a central cache of SAXBuilders (one to
> start with) and allowed clients of the cache to add EntityResolver 
> instances
> to locally return entities.  My single EntityResolver just goes through
> all the client EntityResolvers one by one.
>
>   All was good until I tried parsing multiple documents, then I got a
> JDOMException "Error in building: Stream closed"
>
>   I then went to the SAXBuilder source to look around.  What I found 
> is that
> SAXBuilder always creates a new parser in the build method.  So all my 
> efforts
> were misplaced.  It appears that SAXBuilder can't be resued.
>
>   Do you have any comments on this?  Shouldn't I be concerned about 
> the cost of
> creating/configuring parsers every time a new document must be 
> parsed?  One
> case where this seems important is a web service that needs to handle XML
> messages (like a service using SOAP).
>
>   Is there a way to reuse a SAXBuilder and not create a new parser for 
> every
> document?
>
>   Thanks for any advice you have.
>
> Kim Gillies
>
>





More information about the jdom-interest mailing list