[jdom-interest] Writing large XML files

New, Cecil (GEAE) cecil.new at ae.ge.com
Tue May 13 14:19:36 PDT 2003


if the output after creation of the jDOM is the file, why not just go straight
to the file and skip JDOM altogether.  XML is just text after all. :-)

-----Original Message-----
From: Subrahmanian, Sundararaman V [IT]
[mailto:sundararaman.v.subrahmanian at citigroup.com]
Sent: Tuesday, May 13, 2003 10:10 AM
To: 'jdom-interest at jdom.org'
Subject: [jdom-interest] Writing large XML files


I have a situation where I have to write a huge file.  If all the data that
is to be persisted as XML is converted to XML it might result in more than
10,000 elements.  I am pasting here a simple fragment of the code that I am
using to write the XML elements.  At some point of time, the program
suddenly aborts without any trace message.  

I am using jdom-b8 and jdk version java 1.3.1-b24.  I have the following
questions:

1.  Should I be writing the elements in smaller chunks?  If so, how do I do
it?
2.  Will going over to jdom-b9 help?  I would not want to do this right now.
3.  Also this section gets iterated over several times - is it possible that
the elements created in the previous iteration have not been freed yet by
the garbage collector and hence causing huge memory usage?

Code fragment:  (I had put 2 try-catch blocks for debugging purposes)

		Element rootElement;
		try {
			rootElement = new Element(id + m_rootElementSuffix);
			Iterator iter = beanMap.keySet().iterator();
			while (iter.hasNext()) {  // contains more than
10,000 elements
				PropertyAccessor propAcc =
(PropertyAccessor)(beanMap.get(iter.next()));
				Element element = writeElement(id, propAcc);
// writes the content of propAcc as an XML element
				rootElement.addContent(element);
			}
		} catch (Throwable t) {
			LogMgr.info(this, t.getMessage());
			throw new RuntimeException("Creating elements: " +
t.getMessage());  // t.getMessage() returns null
		}

		Writer writer = null;
		try {
			m_document.setRootElement(rootElement);  //
m_document is a class member
			m_document.setDocType(docType);
			writer = createWriter(id);
// creates a BufferedWriter
			m_outputter.output(m_document, writer);
		} catch (Throwable t) {
			LogMgr.info(this, t.getMessage());
			throw new RuntimeException("Writing elements: " +
t.getMessage());
		} finally {
			try {
				if (writer != null) { writer.close(); }
			} catch (IOException e) {
				throw new RuntimeException(e.getMessage());
			}
		}		

Any help in this regard will be appreciated.

Thanking you,
SVS
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.co
m



More information about the jdom-interest mailing list