[librecat-dev] From Catmandu::Importer::SRU to MARC::Record

Magnus Enger magnus at enger.priv.no
Wed Oct 26 08:40:02 CEST 2016


Dear community!

I am trying to fetch records with Catmandu::Importer::SRU, massage
them and turn them into MARC::Records, for importing into Koha.

The fetching of the records works nicely:

    my $importer = Catmandu::Importer::SRU->new(
        base => 'http://api.libris.kb.se/sru/libris', # Libris SRU endpoint
        query => 'rec.recordIdentifier=636970',
        recordSchema => 'marcxml',
        parser => 'marcxml',
    );

Records are in MARCXML and are parsed nicely into a structure like this:

$VAR1 = {
          'recordData' => {
                          'record' => [
                                      {
                                        'controlfield' => [ ... ],
                                        'leader' => '00525nam a22001813  4500',
                                        'datafield' => [ ... ],
                                        'xmlns' =>
'http://www.loc.gov/MARC21/slim'
                                      }
                                    ]
                        },
          'recordPacking' => 'xml',
          'recordSchema' => 'info:srw/schema/1/marcxml-v1.1',
          'recordIdentifier' => '636970'
        };

What I can't get my head around is how to turn that into a
MARC::Record, that I can import into Koha. From reading the docs I
thought this should work:

    my $record;
    my $exporter = Catmandu->exporter('MARC', file => \$record );
    $exporter->add_many($importer);

But dumping $record only gives:

$VAR1 = '00026     2200025   4500  ';

Or, specifying XML:

    my $record;
    my $exporter = Catmandu->exporter('MARC', file => \$record, type => "XML" );
    $exporter->add_many($importer);

$VAR1 = '<?xml version="1.0" encoding="UTF-8"?>
<marc:collection
xmlns:marc="http://www.loc.gov/MARC21/slim"><marc:record></marc:record>';

Anyone got any tips on how to turn the records from
Catmandu::Importer::SRU into MARC::Record's?

Best regards,
Magnus Enger
Libriotech


More information about the librecat-dev mailing list