Hi, I am executing a program that parses some XML files and stores the extracted data into a database. There are many files with size ranging from 1.72 KB to 6.5 MB. When I am parsing the files using DOMParser, the program executes successfully. It parses some files and then terminates its execution by giving the following output:
When I re-execute the program and start from the file which was last processed in the previous execution, the program runs successfully. Can anyone help me out in finding what the problem is? Also, will SAX processing speed up the program execution and avoid such errors from getting thrown?
Originally posted by Ketan Chachad: Also, will SAX processing speed up the program execution and avoid such errors from getting thrown?
I would say its better if you use SAX as your xml file may vary from 1kb to 6.5MB and also you are only retrieving the data and not changing any data in the XML file., this should increase the processing speed with less memory consumption.
Thanks Balaji for the suggestion and SAX is working perfectly fine. But is the OutOfMemoryError because the system I am currently working on has low memory? I mean will increasing the memory capacity allow me to use DOMParser?
A DOM parser builds a huge structure in memory with objects for everything in your XML file. Since all the text becomes String objects using 16 bits per character and there is all the overhead required for other parts of the structure, you are talking a huge memory requirement. So, the answer is yes, increasing the Java memory allocation will let you handle larger documents with DOM. Bill