Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient way to read a small part of a BIG XML file in Java

We have a new requirement:

There are some BIG xml files keep coming into our system and we will need to process them immediately and quickly using Java. The file is huge but the required information for our processing is inside a element which is very small. ... ...

What is the best way to extract this small portion of the data from the huge file before we start processing. If we try to load the entire file, we will get out of memory error immediately due to size. What is the efficient way in Java that I can use to get the ..data..data..data.. data element without loading or reading the file line by line. Is there any SAX Parser that I can use to get this done?

Thank you

like image 423
java_mouse Avatar asked Dec 21 '22 17:12

java_mouse


1 Answers

The SAX parsers are event based and are much faster because they do what you need: they don't read the xml document entirely. There is a SAXParser available in the Java distributions.

like image 58
Dan D. Avatar answered Dec 24 '22 00:12

Dan D.