Oct 312012
Article Perl

In our previous post we have explained how to process a file in XML format using the XML::Simple module from CPAN.

However, that module works by reading the whole file in memory. This is not suitable if the file to be processed is large and the RAM memory resources available are limited.

Instead, we can use the XML::Parse::PerlSAX module (SAX stands for “Simple API for XML”). Using this module, the file is read as a data stream, and events such as “start of element”, “end of element”, etc. are generated. The programmer needs only to provide an event handler package implementing methods to process these standard events.


In the “XMLReader” package, the methods “start_element”, “end_element” and “characters” are implemented to process the corresponding events:

If we execute this sample program to read the “customers.xml” file introduced in our previous post, the output is:

 Posted by at 8:05 pm

 Leave a Reply