[jdom-interest] How to find document size

Jasmin_Mehta at nexweb.org Jasmin_Mehta at nexweb.org
Fri Jan 18 05:52:43 PST 2008

I do not want to get any io done while I am creating xml document from one 
database and sending it to other after processing it on the fly. This will 
be batch process and can have huge amount of records while executing batch 
each time. 

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 

the algorithm - something like:

1)      ArrayList finalXmlDocumentList = new ArrayList();

2)      org.jdom.Document  accumulatedXmlDoc = new Document();

for (i = 0; i < newXmlDocs.size; i++)
        sizeOfDocument =  FIND SIZE OF accumulatedXmlDoc
        if (accumulatedXmlDoc is not sizeOfDocument )
            accumulatedXmlDoc = accumulatedXmlDoc + newXmlDocs[i];   // 
here actual jdom api is used to concet 2 xml docs.
            finalXmlDocumentList .add(accumulatedXmlDoc ); 
            accumulatedXmlDoc  = new  Document();
            accumulatedXmlDoc = accumulatedXmlDoc + newXmlDocs[i]; // here 
actual jdom api is used to concet 2 xml docs.

4)      use finalXmlDocumentList  further

I would like to know the size for one-liner format XML. You mentioned 
about storeing in byte[], how woule I do that? Would it create performace 


frode at fritid.as 
01/17/2008 04:20 PM

Jasmin_Mehta at nexweb.org

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


The physical size of the file produced when outputting the document will 
vary depending on formatting ;pretty-format
takes more space than a one-liner, and encoding (UTF-8 encoding creates 
some double-byte characters).

The filesize will also depend on platform (windows/Linux) because of the 
varying representation of CRFL (especially with
pretty-print, since this generates a lot of linefeeds)

The only way to know exactly, is to actually write it to disk ans check 
size. A system-independent size can be obtained
by outputting to a byte[] and check for length of this.

You could also create the document with zero, one and two empty elements 
(all tags included, but no content) and take
the zero-one + the difference between 1 and 2 times the number of 
elements, and on-the-fly calculate the total length of
of each element's content and add it up as you go along. A lot of code, 
but if the elements are the same with different
content this should not be an awful lot of work.


             Jasmin_Mehta at nexweb.org   
             Sent by:  
             jdom-interest-bounces at jdom.org             To 
 <jdom-interest at jdom.org> 
             17.01.2008 21:34  
How to find document size 


My requirement is to keep populating elements to one xml document object 
until it reaches to certain size. Which JDOM
API can help to find the size of create new XML  org.jdom.Document?


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

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

More information about the jdom-interest mailing list