This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread 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 Murach's Java Servlets and JSP this week in the Servlets 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
Author

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.
--Thanks


Bhasker Reddy
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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]
 
Consider Paul's rocket mass heater.
 
subject: SAX vs DOM, which is better
 
Similar Threads
suggest me an approach to parse a large xml file
abt xml
Storing SAX Parser data into MySql
Meaning of XML
what is SAX (event-based) parsing ?