version 1.1, 2004/06/17 15:58:42
|
version 1.4, 2004/07/13 18:32:49
|
Line 11 use base qw(XML::SAX::Base);
|
Line 11 use base qw(XML::SAX::Base);
|
use lib '/usr/local/mpiwg/archive'; |
use lib '/usr/local/mpiwg/archive'; |
use MPIWGStor; |
use MPIWGStor; |
|
|
|
my $debugElem = 0; |
|
my $debugCont = 0; |
|
|
my @currElemPath; |
my @currElemPath; |
my $currElem; |
my $currElem; |
my $currText; |
my $currText; |
Line 24 sub getData {
|
Line 27 sub getData {
|
sub start_document { |
sub start_document { |
my ($self, $doc) = @_; |
my ($self, $doc) = @_; |
# process document start event |
# process document start event |
#logger('DEBUG', "startdoc: $self, $doc"); |
logger('DEBUG', "startdoc: $self, $doc") if ($debugElem); |
@currElemPath = (); |
@currElemPath = (); |
$currElem = ""; |
$currElem = ""; |
$currText = ""; |
$currText = ""; |
Line 35 sub start_document {
|
Line 38 sub start_document {
|
sub start_element { |
sub start_element { |
my ($self, $el) = @_; |
my ($self, $el) = @_; |
# process element start event |
# 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 |
# check if the last element needs to be finished |
if ($currElem) { |
if ($currElem) { |
my $elem = join "/", @currElemPath; |
my $elem = join "/", @currElemPath; |
push @elements, [$elem, "", $currAttrib]; |
push @elements, [$elem, "", $currAttrib]; |
} |
} |
# element name is either LocalName or Name |
# element name is either LocalName or Name |
my $name = $$el{'LocalName'}; |
my $name = $$el{'LocalName'} or $$el{'Name'}; |
$name = $$el{'Name'} unless ($name); |
|
#logger('DEBUG', " name: $name"); |
#logger('DEBUG', " name: $name"); |
# assemble attributes string |
# assemble attributes string |
$currAttrib =""; |
$currAttrib =""; |
foreach $a (values %{$$el{'Attributes'}}) { |
foreach my $attr (values %{$$el{'Attributes'}}) { |
my $n = $$a{'LocalName'}; |
my $key = $$attr{'LocalName'} or $$attr{'Name'}; |
$n = $$a{'Name'} unless ($n); |
my $val = $$attr{'Value'}; |
my $v = $$a{'Value'}; |
$currAttrib .= "$key=\"$val\" "; |
$currAttrib .= "$n=\"$v\" "; |
|
} |
} |
|
$currAttrib = sstrip($currAttrib); |
# start element name |
# start element name |
push @currElemPath, $name; |
push @currElemPath, $name; |
$currElem = $name; |
$currElem = $name; |
Line 62 sub start_element {
|
Line 64 sub start_element {
|
sub end_element { |
sub end_element { |
my ($self, $el) = @_; |
my ($self, $el) = @_; |
# process element end event |
# process element end event |
#logger('DEBUG', "endelem: $self, $el"); |
logger('DEBUG', "endelem: $self, $$el{'LocalName'}") if ($debugElem); |
# check element name |
# check element name |
my $name = $$el{'LocalName'}; |
my $name = $$el{'LocalName'} or $$el{'Name'}; |
$name = $$el{'Name'} unless ($name); |
|
my $lastag = $currElemPath[$#currElemPath]; |
my $lastag = $currElemPath[$#currElemPath]; |
if ($lastag ne $name) { |
if ($lastag ne $name) { |
logger('ERROR', "closing tag '$lastag' doesn't match '$name'!"); |
logger('ERROR', "closing tag '$lastag' doesn't match '$name'!"); |
Line 75 sub end_element {
|
Line 76 sub end_element {
|
# strip whitespace from element content |
# strip whitespace from element content |
$currText =~ s/^\s*//; |
$currText =~ s/^\s*//; |
$currText =~ s/\s*$//; |
$currText =~ s/\s*$//; |
if ($currText) { |
if (($currText)||($currAttrib)) { |
# put pair in elements array |
# put pair in elements array |
push @elements, [$elem, $currText, $currAttrib]; |
push @elements, [$elem, $currText, $currAttrib]; |
#logger('DEBUG', " elem: $elem = $currText"); |
logger('DEBUG', " elem: $elem = $currText ($currAttrib)") if ($debugCont); |
} |
} |
# end element name |
# end element name |
pop @currElemPath; |
pop @currElemPath; |
Line 90 sub end_element {
|
Line 91 sub end_element {
|
sub characters { |
sub characters { |
my ($self, $char) = @_; |
my ($self, $char) = @_; |
# process character data event |
# process character data event |
#logger('DEBUG', "characters: $self, $char"); |
logger('DEBUG', "characters: $self, $char") if ($debugElem > 1); |
# add to current content |
# add to current content |
$currText .= $$char{'Data'}; |
$currText .= $$char{'Data'}; |
#logger('DEBUG', " Text: $currText"); |
logger('DEBUG', " Text: $currText") if ($debugCont > 1); |
} |
} |
|
|
|
|