This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
The moose likes XML and Related Technologies and the fly likes SAX vs DOM, which is better Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "SAX vs DOM, which is better" Watch "SAX vs DOM, which is better" New topic

SAX vs DOM, which is better

Bhasker Reddy
Ranch Hand

Joined: Jun 13, 2000
Posts: 176
I need to parse XML documents and convert them into specific record types based test file. I created this application using DOM parser. But I can process only 3 gigs of data an hour. My boss wants me to use SAX parser. I need to process gigs of data. Probably around 300 gigs a day. Each data file is inturn group of multiple small files(each with200 kb to 1mb). I split these files into small files and parse them using DOM and output to a text file. Do you think SAX is better than DOM. For SAX don't i need to split the file, can I just open the file and write it out to text file.

Bhasker Reddy
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
SAX parsers work on streams of events instead of reading the whole document into memory at once. That makes it perform better than DOM.

You could try to write a SAX handler (extend DefaultHandler or implement ContentHandler) which collects a single record (whatever that is) based on the events it receives from the SAX parser, writes that record into the output file, collects the next record based on events, writes that record, and so forth.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: SAX vs DOM, which is better