++ed by:

1 PAUSE user
2 non-PAUSE users.

Thomas Berger
and 2 contributors


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



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);
 my $rootEL = { Name => '{}ROOT',
           LocalName => 'ROOT',
        NamespaceURI => "",
              Prefix => "",
          Attributes => {}

 # 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,

 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