example of thisalthough we won' review it here because it doesn' really show anything new parsing xml with sax (simple api for xml|unlike the element tree and domwhich represent an entire xml document in memorysax parsers work incrementallywhich can potentially be both faster and less memory-hungry performance advantage cannot be assumedhoweverespecially since both the element tree and dom use the fast expat parser sax parsers work by announcing "parsing eventswhen they encounter start tagsend tagsand other xml elements to be able to handle those events that we are interested in we must create suitable handler classand provide certain predefined methods which are called when matching parsing events take place the most commonly implemented handler is content handleralthough it is possible to provide error handlers and other handlers if we want finer control here is the complete import_xml_sax(method it is very short because most of the work is done by the custom incidentsaxhandler classdef import_xml_sax(selffilename)fh none tryhandler incidentsaxhandler(selfparser xml sax make_parser(parser setcontenthandler(handlerparser parse(filenamereturn true except (environmenterrorvalueerrorincidenterrorxml sax saxparseexceptionas errprint("{ }import error{ }formatos path basename(sys argv[ ])err)return false we create the one handler we want to use and then we create sax parser and set its content handler to be the one we have created then we give the filename to the parser' parse(method and return true if no parsing errors occurred we pass self ( this incidentcollection dict subclassto the custom incidentsaxhandler class' initializer the handler clears the old incidents away and then builds up dictionary of incidents as the file is parsed once the parse is complete the dictionary contains all the incidents that have been read