XML Parser: DOM Based or Event Based Parser

There are basically two types of xml parser: one is DOM-based XML parser and another is Event-based XML parser. You have two choices to select from. In DOM based XML parsing, data is treated as tree based structure and in event-based parsing, parser sees you data as series of event like opening element, closing element and so on. Both DOM-based and Event-based parsers have advantages and disadvantages. Your choice will depends on how you want to use your XML data. DOM-based loads all the XML data into memory and event-based loads part of the XML data into memory. DOM-based parser can validate your XML data but event-based parser cannot validate your data as event-based parser does not load whole data in memory. Event-based parser is fast compared to DOM-based parser. Event-based parser is data-centric and DOM based parser is document-centric. Event-based parser is suitable for sequential parsing of document whereas DOM based parser is suitable for xml data to be read repeatedly or out of sequence order.