Advantages of Event-Driven Parsers

Event-driven parsers have several advantages over tree-based parsers.

An event-driven parser can handle huge amounts of XML data. Let’s say that you need to parse XML data in a file that is hundreds of megabytes in size. The parser works through the file, reading each line, triggering events when they’re needed. A DOM-based parser would need to read the entire file into memory at once, something that might be difficult on smaller PCs or workstations. So, for the same XML data, a DOM-based parser requires more memory. Depending on the size of the XML data, it can be impractical (or even impossible) to use a DOM-based parser.

Another advantage of an event-driven parser is the complete XML file doesn’t need ...

Get XML and Perl now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.