[jdom-interest] How to find document size

Laurent Bihanic laurent.bihanic at atosorigin.com
Fri Jan 18 06:59:12 PST 2008


Hi,

To avoid useless memory allocation, I know no other method than serializing 
the document (using XMLOutputter) to a special OutputStream implementation 
that will count the number of bytes being written and throw the data away.

But be careful because XMl serialization has a cost, CPU-wise.

Regards,

Laurent


Jasmin_Mehta at nexweb.org a écrit :
> 
> 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();
> 
> 3)
> 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.
>         }
>         else
>         {
>              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 issue?
> 
> Thanks
> Jasmin


More information about the jdom-interest mailing list