[jdom-interest] How to find document size

Tatu Saloranta cowtowncoder at yahoo.com
Fri Jan 18 09:51:36 PST 2008


--- Jasmin_Mehta at nexweb.org wrote:

> I need to know the xml document size as it is when
> it comes out from 
> Oracle's 'XMLTYPE' datatype. I am appending
> resultset records one after 
> another in one xml document until it reaches certain
> size. For this 
> purpose I need to know the size of 

There is no efficient way to get exact size; either
for serialized or amount of memory Java uses for the
JDOM tree. To know exact size, you have to serialize
it: and even when using dummy OutputStream there's
linear cost for doing that, and with incremental
calls, it has N^2 complexity (essentially dog slow for
sizable docs).

But you can approximate size yourself; this would give
rough idea of either serialized size or amount of
memory used to store the JDOM tree in memory (latter
which is usually 3x - 4x of the former, depending on
kind of document).

The main question is what is this to be used for?
To avoid getting a DB exception from Oracle (there's a
max size for column), to avoid Denial-of-service
attack (memory used on server side for processing doc)
or something else?
As long as approximate size is enough (size that's
within, say, 2x of the actual size) it should be
doable quite efficiently.

-+ Tatu +-



      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs


More information about the jdom-interest mailing list