I have a Java program that is generating XML data which happens to be very large. I am using the typical parsers in javax.xml and the org.w3c.dom objects. The DOM in memory is becoming so large that it occasionally runs out of memory. Now, the reason it reaches the memory limit is because the program is generating all of the data at once and then transforming it to a String and then to a file. There are hundreds of elements being generated at once that could be made one at a time and buffered to a file rather than slowly filling the RAM. I’ve been looking into libraries out there but I’m a bit confused on what is good. What method should I be using to buffer this DOM document to a file rather than generating all at once?
Share
Yes Marty, I also suggest you to use the SAX. It consumes less memory.
Here’s a simple sample code for SAX implementation.