#!/usr/bin/perl use warnings; use strict; $|++; use XML::SAX::Machines qw( :all ); my $output_handle; # global stream output container ## # callback for end_document event. my $write_hook = sub { my $self = shift; my $current_doc = $output_handle; # get contents of output buffer $output_handle = ''; # clear buffer for next doc ## process current doc process_doc( $current_doc ); }; my $filter = EndDocumentAction->new(end_hook => $write_hook); my $machine = Pipeline( ByRecord( $filter ), \$output_handle, ); $machine->parse_file( \*DATA ); sub process_doc { my $content = shift; # do something interesting print $content, "\n"; } package EndDocumentAction; use base qw( XML::SAX::Base ); sub new { my ($class, %args) = @_; my $self = {}; $self->{End_Hook} = $args{end_hook}; # install callback for end_document $self->{start_counter} = 0; bless $self, $class; return $self; } sub end_document { my $self = shift; my $callback = $self->{End_Hook}; $self->$callback(); } 1; __END__ hey man hey man, how's it goin'? pretty right on.