[jdom-interest] Re: Reading XML with JDOM
cowtowncoder at yahoo.com
Fri Oct 3 13:41:01 PDT 2008
--- On Fri, 10/3/08, David Wall <david.wall at myeastside.com> wrote:
> Michael has it right -- penny-wise and pound foolish
> won't result in a
> good performing system.
Agreed. And if network _latency_ is the problem, generally batching of multiple requests and using pipelining (both for http, and in general pipelined processing) can help more here.
> If your XML is really that simple, maybe XML parsing it is
> not even the right solution, though SAX would surely do well. Much
> XML parsers are very general, so they are very useful. But if your data
> is simple, you may find simple string parsing yourself to
> be the fastest.
I 100% disagree. One should never ever ever try use to use simple String for doing job of an xml parser if a good parser is available.
Likewise, it seldom makes sense to use String appends for xml generation. Those are among biggest anti-patterns in simpl(e|istic) xml processing.
In both cases you will end up with slower not faster performance; but most importantly will probably hit most common problems with such approach (quoting of less-thans and ampersands; encoding issues, assuming formatting wrt. white space, forgetting about CDATA sections, comments, PIs and so on).
And even performance-wise current xml parsers (sax and stax) are ridiculously heavily optimized and do good job at working fast.
You can benchmark approaches to see for yourself, but I have yet to see a case where hand-written string scanner made sense.
And finally, JDOM is not an xml parser (I hope that's what FAQ says): it is true that building a tree model is overhead that is relatively easy to eliminate.
My advice would really be to look at JAXB ref. implementation (javax.xml.bind), coupled with a fast Sax or Stax parser. That is a very convenient and high performance combo, and sounds like a good fit for the original use case.
-+ Tatu +-
More information about the jdom-interest