#!/usr/bin/perl -w use strict; use XML::Parser; my $parser = new XML::Parser( Style => "::localParser" ); print $parser->parsefile( $ARGV[0] ); ######################################################### ######################################################### parser ######################################################### package localParser; use strict; # # called when the parser starts # sub Init { my $self = shift(); $self->{people} = []; $self->{officers} = []; $self->{text} = ''; } sub Start { my ($self, $element, %attr) = @_; $self->{text} = ''; # clear text to be sure } sub Char { my ($self, $string) = @_; $self->{text} .= $string; # append string to text } sub End { my ($self, $element) = @_; # save string in proper # category. if you have # more complicated data # (i.e. a simple array # won't do), you'll have # to do something more # clever if ( $element eq 'Ch_Chair' ) { push( @{$self->{officers}}, $self->{text} ); } elsif ( $element eq 'CommitteeList' ) { push( @{$self->{people}}, $self->{text} ); } $self->{text} = ''; } # # the final output # sub Final { my $self = shift(); my $officers = join("\n\t\t\t", map{ "$_" } @{$self->{officers}}); my $people = join("\n\t\t\t", map{ "$_" } @{$self->{people}}); return <<__HERE__ $officers $people __HERE__ } 1;