473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to load a big XML file in Java

ThatThatGuy
449 Expert 256MB
What is the best way to load a big XML file that's 20-40 MB in size?
I have tried using DOMParser and DocumentBuilder but, all I get is the following as an error:

java.lang.OutOfMemoryError: Java heap space
May 18 '10 #1
10 3461
jkmyoung
2,057 Expert 2GB
1. Do you really need the whole XML document to be loaded into a DOM structure? What are you trying to do with it?
If you can look at alternatives, see SAX, or VTD, other alternatives that don't require full loading into memory. Perhaps all you need is some sort of XMLStreamReader.

2. You could increase the allocated heap space of your java runtime.
May 18 '10 #2
ThatThatGuy
449 Expert 256MB
@jkmyoung
Yes I need the whole XML at a stretch.
May 18 '10 #3
jkmyoung
2,057 Expert 2GB
I meant, all at once?
If so then how are you running your java program?

java -Xms<initial heap size> -Xmx<maximum heap size>
eg: java -Xms32m -Xmx128m
May 18 '10 #4
ThatThatGuy
449 Expert 256MB
@jkmyoung
No it needs to load up 65000 lines of xml tags... i need all of them for my pos application...

Any other methods i can try.... the file is just 7MB
May 19 '10 #5
jkmyoung
2,057 Expert 2GB
So even when you increase the heap size to 512, eg
java -Xms32m -Xmx512m
you still get out of memory errors?
May 19 '10 #6
ThatThatGuy
449 Expert 256MB
@jkmyoung
I dropped the idea of the creating the app in java thanks.
May 20 '10 #7
Dheeraj Joshi
1,123 Expert 1GB
Because you could not load entire XML in one shot? or you dropped this idea because of some other reason?

Regards
Dheeraj Joshi
May 20 '10 #8
ThatThatGuy
449 Expert 256MB
@dheerajjoshim
Since Java can't load XML file that's 7MB(65000 lines long). The thing is that I need to load the xml file at a stretch because I want every data in XML. It's not a setting file it's a whole bunch of data. When I did this in .NET using XmlDocument, it didn't seemed to have a problem.
May 20 '10 #9
jkmyoung
2,057 Expert 2GB
Another alternative I neglected to mention: jdom.

It's still hard to tell what you're doing with the data; thus hard to recommend blindly.
Other possible suggestion:
Is it possible to load this into a db and let the db do the gruntwork of whatever you want to do?
May 20 '10 #10
Dheeraj Joshi
1,123 Expert 1GB
I don't know why you are not able to load 7 Mb in one shot. Once I successfully loaded 15 Mb XML file in one shot.

Regards
Dheeraj Joshi
May 21 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: John T. McDougald | last post by:
I am using a Win XP Home system and I have had a problem ever since I first bought it. Whenever I am on the net and come on to a web site that has a Jaava enabled website, my system slows down...
0
by: mailkhurana | last post by:
Hii , I am trying to use a type 2 driver to connect to DB2 0n AIX 5 I have a small java test to class to establish a conneciton with the db .. I am NOT using WAS or any appserver When I try to...
3
by: anagai | last post by:
hi I am trying to install the java bridge library for php 5.1.2. I have installed the j2see 1.4 and jdk. I have setup the section in php.ini as follows: java.classpath =...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
1
by: skchonghk | last post by:
Dear all smart experts, I write a simple Java UDF, which should run on DB2 v8 on AIX. But it can't load the Java class. Help ugently needed!! Thanks! I develop and deploy the Java UDF with...
1
by: bea | last post by:
Hi. I'm trying to call a stored procedure and it executes a external Java class but I have this error: SQL4304N Java stored procedure or user-defined function "SENDMAIL", specific name...
0
by: Manasi12 | last post by:
Hi, I am trying to load number of jar files. But while giving load java command I am getting a bunch of errors for the jar files. I am using oracle 9i. The jar files are...
1
by: ramyageethika8 | last post by:
hai, i would be happy if anyone helps me on loading java software on to my system and let me know the configurations and reqirments to load java
1
by: okonita | last post by:
Hello all, I have a Java problem that I hope can be answered here. Very new to DB2 UDB and UDF (we are on DB2v9.5, Linux and Windows), I have managed to get the UDF registered but having problem...
6
by: Time Waster | last post by:
Java property files are dead simple: key1=val1 some.key2=val2 For simplicity on the Java side, I'd like to use these files from C as well (the C program and Java program must cooperate). ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.