#!/bin/perl use strict; use warnings; use XML::Parser; my %elements; my $parser = XML::Parser->new( Handlers => { Start=>\&handle_start, End=>\&handle_end, Char=>\&char_handler }); # specify xml file on command line foreach my $file ( @ARGV ) { eval { $parser->parsefile( $file ) }; die "can't parse file: $@" if $@; } sub handle_start { my( $expat, $element, %attrs ) = @_; if( %attrs ) { print "\t$element attributes:\n"; while( my( $key, $value ) = each( %attrs )) { print "\t\t$key => $value\n"; } } } sub char_handler { my ($p, $data) = @_; my $inf = $elements{$p->current_element}; if ($data =~ /\S/) {print "\t$data\n";} } sub handle_end { my( $expat, $element ) = @_; # print "$element\n"; }