--- foxridge-archiver/HarvestmetaHandler.pm 2004/06/17 15:58:42 1.1 +++ foxridge-archiver/HarvestmetaHandler.pm 2004/07/08 21:22:04 1.2 @@ -8,15 +8,18 @@ use strict; use base qw(XML::SAX::Base); -use lib '/usr/local/mpiwg/archive'; +use lib '/usr/local/mpiwg/archive_devel'; use MPIWGStor; +my $debugElem = 0; +my $debugCont = 0; + my @currElemPath; my $currElem; my $currText; my $currAttrib; my @elements; - + sub getData { return @elements; } @@ -24,7 +27,7 @@ sub getData { sub start_document { my ($self, $doc) = @_; # process document start event - #logger('DEBUG', "startdoc: $self, $doc"); + logger('DEBUG', "startdoc: $self, $doc") if ($debugElem); @currElemPath = (); $currElem = ""; $currText = ""; @@ -35,7 +38,7 @@ sub start_document { sub start_element { my ($self, $el) = @_; # process element start event - #logger('DEBUG', "startelem: $self, $el"); + logger('DEBUG', "startelem: $self, $$el{'LocalName'}") if ($debugElem); # check if the last element needs to be finished if ($currElem) { my $elem = join "/", @currElemPath; @@ -47,12 +50,13 @@ sub start_element { #logger('DEBUG', " name: $name"); # assemble attributes string $currAttrib =""; - foreach $a (values %{$$el{'Attributes'}}) { - my $n = $$a{'LocalName'}; - $n = $$a{'Name'} unless ($n); - my $v = $$a{'Value'}; - $currAttrib .= "$n=\"$v\" "; + foreach my $attr (values %{$$el{'Attributes'}}) { + my $key = $$attr{'LocalName'}; + $key = $$attr{'Name'} unless ($key); + my $val = $$attr{'Value'}; + $currAttrib .= "$key=\"$val\" "; } + $currAttrib = sstrip($currAttrib); # start element name push @currElemPath, $name; $currElem = $name; @@ -62,7 +66,7 @@ sub start_element { sub end_element { my ($self, $el) = @_; # process element end event - #logger('DEBUG', "endelem: $self, $el"); + logger('DEBUG', "endelem: $self, $$el{'LocalName'}") if ($debugElem); # check element name my $name = $$el{'LocalName'}; $name = $$el{'Name'} unless ($name); @@ -75,10 +79,10 @@ sub end_element { # strip whitespace from element content $currText =~ s/^\s*//; $currText =~ s/\s*$//; - if ($currText) { + if (($currText)||($currAttrib)) { # put pair in elements array push @elements, [$elem, $currText, $currAttrib]; - #logger('DEBUG', " elem: $elem = $currText"); + logger('DEBUG', " elem: $elem = $currText ($currAttrib)") if ($debugCont); } # end element name pop @currElemPath; @@ -90,10 +94,10 @@ sub end_element { sub characters { my ($self, $char) = @_; # process character data event - #logger('DEBUG', "characters: $self, $char"); + logger('DEBUG', "characters: $self, $char") if ($debugElem); # add to current content $currText .= $$char{'Data'}; - #logger('DEBUG', " Text: $currText"); + logger('DEBUG', " Text: $currText") if ($debugCont); }