[XOM-interest] Appending at the end of an Xml file efficiently
Tatu Saloranta
cowtowncoder at yahoo.com
Sat Jun 20 12:13:13 EDT 2009
--- On Sat, 6/20/09, Elliotte Harold <elharo at ibiblio.org> wrote:
> Anvesh Vagiri<yahanvesh at gmail.com>
> wrote:
> > hi,
> >
> > I am just a newbie to XOM, and i need to append nodes to an existing
> > xml file always at the end I used the code available here.
> >
> > http://marc.info/?l=xom-interest&m=117286293113470&w=2
> >
> > But unfortunately it gives Out of memory error in my java netbeans
> > when the file size increases more than just 10-15MB.
> >
>
> 1. Try running the code outside NetBeans.
> 2. Use a profiler to see where the memory is going, and if
> you have memory leak somewhere.
It is also possible that it's just because of default heap size (64M), and typical expanse ratio of a tree model (3x - 5x) means that all memory is getting used. If so, increasing heap size would overcome problem for this case.
But if significantly bigger documents are to be handled, the usual solution is to either process document sub-tree at a time (if it's record-based and this is possible), or use a lower-level abstraction like streaming parser & generator. This would be done by reading through existing document up until addition point, copying content through, and then starting to add content after this.
My personal favorite is StaxMate (http://staxmate.codehaus.org/Tutorial), but I am bit biased.
-+ Tatu +-
More information about the XOM-interest
mailing list