Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6865327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:01:47+00:00 2026-05-27T03:01:47+00:00

I have a Java program that is generating XML data which happens to be

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:01:48+00:00Added an answer on May 27, 2026 at 3:01 am

    Yes Marty, I also suggest you to use the SAX. It consumes less memory.
    Here’s a simple sample code for SAX implementation.

    public class SaxReader{
        public void readXML() throws Exception{
            ResultHandler oHandler                      = new ResultHandler();
            CreateParser parser                         = new CreateParser(oHandler);    
            String responseXML = "Place your XML as String HERE";
            InputSource input                                   = new InputSource(new StringReader(responseXml)); 
            input.setEncoding("UTF-8");     
            parser.parse(input);
    
        }
    }
    
    
    class ResultHandler extends DefaultHandler {
        public void startDocument (){
            System.out.println("Start document");
        }
    
        public void endDocument (){
            System.out.println("End document");
        }
    
        public void startElement(String namespaceURI, String localName, String qName, Attributes attribs)throws SAXException {
            strValue = "";
            if(null!=qName && qName.equals("ID")){
                System.out.println("Starting element <ID> : "+strValue);
            }
        }
    
        public void characters(char[] ch, int start, int length)throws SAXException {
            strValue += new String(ch, start, length);
            System.out.println(">>>" + strValue);//Reading the values.
        }
    
        public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
            if(null!=qName && qName.equals("ID")){
                System.out.println("Ending element </ID> : "+strValue);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

actually i have a java program that reads the data from a specific XML
We have a java program that requires a large amount of heap space -
I have a Java program that opens a file using the RandomAccessFile class. I'd
I have a Java program that is constantly being sent UDP data from an
I have a Java program that reads in a large list of strings from
I have a java program that stops often due to errors which is logged
I have a Java program that loads thirdparty class files (classes I did not
I have a Java program that runs many small simulations. It runs a genetic
I have a java program that will work with a variety of Java Beans.
I have a Java program that executes from Spring Qquartz every 20 seconds. Sometimes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.