--- foxridge-archiver/HarvestmetaHandler.pm 2004/06/17 15:58:42 1.1.1.1 +++ foxridge-archiver/HarvestmetaHandler.pm 2004/07/13 18:32:49 1.4 @@ -11,12 +11,15 @@ use base qw(XML::SAX::Base); use lib '/usr/local/mpiwg/archive'; 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,24 +38,23 @@ 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; push @elements, [$elem, "", $currAttrib]; } # element name is either LocalName or Name - my $name = $$el{'LocalName'}; - $name = $$el{'Name'} unless ($name); + my $name = $$el{'LocalName'} or $$el{'Name'}; #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\" "; + $currAttrib = ""; + foreach my $attr (values %{$$el{'Attributes'}}) { + my $key = $$attr{'LocalName'} or $$attr{'Name'}; + my $val = $$attr{'Value'}; + $currAttrib .= "$key=\"$val\" "; } + $currAttrib = sstrip($currAttrib); # start element name push @currElemPath, $name; $currElem = $name; @@ -62,10 +64,9 @@ 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); + my $name = $$el{'LocalName'} or $$el{'Name'}; my $lastag = $currElemPath[$#currElemPath]; if ($lastag ne $name) { logger('ERROR', "closing tag '$lastag' doesn't match '$name'!"); @@ -75,10 +76,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 +91,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 > 1); # add to current content $currText .= $$char{'Data'}; - #logger('DEBUG', " Text: $currText"); + logger('DEBUG', " Text: $currText") if ($debugCont > 1); }