Re: How to find document size

Tatu Saloranta <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
--- [email protected] 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
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.