Re: XML parser and writer
I have ... little
experience processing XML with Java.
My first use of Java for XML was using SAX. SAX is fast - you can parse an
entire document in a single pass and do things with what you find. If what
you do is build an in-memory structure, you can customize the structure to
your heart's content, modifying and altering elements as you retrieve them.
What you end up with internally has little conceptually or structurally to do
with XML any more; you've extracted all the juice from the XML and thrown away
SAX isn't all that easy at first in that it is built on callbacks. People who
use Bean and Swing Listeners will grok the event-driven style pretty quickly.
DOM is simpler in way - its structure is an exact mirror of the XML
document's, treating containment by a tag as descent into a tree. If you want
a different in-memory structure, you need to build it separately, making the
DOM tree and your custom structure two separate bodies in cyberspace. This
requires more memory than SAX parsing. OTOH, your DOM tree stays in memory
for repeated mamipulation or query. Complicated operations or transformations
that can't happen in a single pass are straightforward in DOM idioms.
Since DOM maintains its structural parallelism with the XML document, it isn't
hard to write a DOM out to an XML format.