The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::OAI::Record::NamespaceFilter - general filter class

SYNOPSIS

DESCRIPTION

This SAX filter takes a hashref namespaces as argument, with namespace URIs for keys and SAX filters/builders (or undef) for values. It will forward any element belonging to a namespace from this list to the associated SAX filter and all of its children (regardless of their respective namespace) to the same one. It can be used either as a metadataHandler or recordHandler.

 my $parsed;
 $builder = XML::SAX::Writer->new(Output => \$parsed);
 $builder->start_document();
 my $rootEL = { Name => '{}ROOT',
           LocalName => 'ROOT',
        NamespaceURI => "",
              Prefix => "",
          Attributes => {}
              };
 $builder->start_element($rootEL);

 # filter for OAI-Namespace in records: forward all
 $filter = Net::OAI::Harvester::Record::NamespaceFilter(
      'http://www.openarchives.org/OAI/2.0/' => $builder);
 $harvester = Net::OAI::Harvester->new( [
     baseURL => ...,
     recordHandler => $filter,
     ] );

 $list = $harvester->listRecords( 
    metadataPrefix  => 'a_strange_one',
    recordHandler => $filter,
  );

 $builder->end_element($rootEL);
 $builder->end_document();
 print $parsed;

If the list of namespaces ist empty or no handler (builder) is connected to a filter, it effectively acts as a plug to Net::OAI::Harvester. This might come handy if you are planning to get to the raw result gy other means, e.g. by tapping the user agent or accessing the result's xml() method:

 $plug = Net::OAI::Harvester::Record::NamespaceFilter();
 $harvester = Net::OAI::Harvester->new( [
     baseURL => ...,
     recordHandler => $plug,
     ] );

 my $unparsed;
 open (my $TAP, ">", \$unparsed);
 $harvester->userAgent()->add_handler(response_data => sub { 
        my($response, $ua, $h, $data) = @_;
        print $TAP $data;
     });

 $list = $harvester->listRecords( 
    metadataPrefix  => 'a_strange_one',
    recordHandler => $plug,
  );

 print $unparsed;     # complete OAI response
 print $list->xml();  # should be the same

METHODS

new()