Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Writing large XML documents

xom-interest AT

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Tatu Saloranta <cowtowncoder AT>
  • To: XOM interest <xom-interest AT>
  • Subject: Re: [XOM-interest] Writing large XML documents
  • Date: Mon, 17 Dec 2007 20:22:50 -0800 (PST)

--- Eric Wang <jemroc AT> wrote:

> Hi Benson, I understand that XOM is about trees, but
> it also provides
> a streaming API for reading large XML documents. I'm

That is bit misleading, in a way -- it's more accurate
to say that you can build tree representations for
sub-trees of xml content (and potentially also discard
earlier parts, trim while you go, if you want to get
fancy). Although underlying parsers are all streaming
(XOM is not a parser but uses underlying parsers like
Xerces), result is still a tree that has to completely
fit in memory.

> currently using
> that API in my application and figured it would have
> the complementary
> ability to write large documents as well.

The problem here is that the requirement is that your
input is a tree and thereby has to fit in memory.
While output writer will generally be streaming (once
again, XOM delegates low-level tasks to a serializer,
using Sax by default, or Stax via Nux extensions), it
does not help a lot. That is, unless you create
separate XOM documents for sub-trees. This is a
potentially workable solution.

Of course, if you can fit documents that you read in
memory, it doesn't take more memory to write them out.

If you don't read input (in this particular case) in
as a XOM tree, there isn't much XOM can do for you.

Writing output using Stax is quite simple. One of
oldest introductions was written by Elliotte:

and writer-side is briefly covered on second page.

More recently, Sun has included Stax api as well as
reference implementation with Java 1.6, tutorial can
be found at:

Hope this helps,

-+ Tatu +-

Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

Archive powered by MHonArc 2.6.24.

Top of Page