package MIS_SAX_Parser; use Data::Dumper; use XML::SAX::Base; @ISA = ('XML::SAX::Base'); use strict; use constant TYPE0 => 0; use constant TYPE1 => 1; use constant TYPE2 => 2; sub new { my ($class, $callback) = @_; my $self = { COUNTER => 0, HASHTYPE => TYPE0 }; bless $self, $class; if ($callback) { $self->{CALLBACK} = \&$callback; } else { $self->{CALLBACK} = \&nocall; } return $self; } sub start_element { my ($self, $data) = @_; if ($data->{Name} eq "Column") { $self->{COLUMN_DATA}->{$data->{Attributes}->{"{}name"}->{Value}} = $data->{Attributes}->{"{}value"}->{Value}; } elsif ($data->{Name} eq "Table") { $self->{TABLE_NAME} = $data->{Attributes}->{"{}name"}->{Value}; } } sub end_element { my ($self, $data) = @_; my $name = $data->{Name}; if ($name eq "Table") { $self->{CALLBACK}->($self->{TABLE_NAME}, $self->{COLUMN_DATA}); # Reset the TABLE_NAME and COLUMN_DATA $self->{TABLE_NAME} = undef; $self->{COLUMN_DATA} = {}; } } # Debug callback function sub nocall { my ($table, $data) = @_; print "Table name is $table\n"; print Dumper($data)."\n\n"; } 1;