[jdom-interest] How to find document size

Michael Kay mike at saxonica.com
Fri Jan 18 11:25:18 PST 2008

Tatu asked you a perfectly reasonable question (how accurate does your
information need to be?), and explained why he was asking. So it seems
rather discourteous to come back with more questions rather than answering
Michael Kay


From: jdom-interest-bounces at jdom.org [mailto:jdom-interest-bounces at jdom.org]
On Behalf Of Jasmin_Mehta at nexweb.org
Sent: 18 January 2008 19:05
To: Tatu Saloranta
Cc: jdom interest
Subject: Re: [jdom-interest] How to find document size

how can I find amount of memory Java uses for JDOM tree? 

and how can I serialize it? 

Tatu Saloranta <cowtowncoder at yahoo.com> 
Sent by: jdom-interest-bounces at jdom.org 

01/18/2008 12:51 PM 

jdom interest <jdom-interest at jdom.org> 


Re: [jdom-interest] How to find document size


--- 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. 
To control your jdom-interest membership:

Our domain name is changing. Please take note of the sender's
e-Mail address and make changes to your personal address list,
if needed. Both domains will continue to work, only for a limited
This email and any files transmitted with it are intended solely for 
the use of the individual or agency to whom they are addressed. 
If you have received this email in error please notify the Navy 
Exchange Service Command e-mail administrator. This footnote 
also confirms that this email message has been scanned for the
presence of computer viruses.

Thank You! 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20080118/f244d1bb/attachment.htm

More information about the jdom-interest mailing list