diff HarvestmetaHandler.pm @ 3:1a51f94d5dbd

new version also reads XML index feeds via HTTP
author casties
date Thu, 08 Jul 2004 23:22:04 +0200
parents 30497c6a3eca
children 046d584ed7b3
line wrap: on
line diff
--- a/HarvestmetaHandler.pm	Thu Jul 08 19:30:05 2004 +0200
+++ b/HarvestmetaHandler.pm	Thu Jul 08 23:22:04 2004 +0200
@@ -8,15 +8,18 @@
 
 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 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_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 @@
     #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 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 @@
     # 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 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);
 }