MarcusBarnes / mik

The Move to Islandora Kit is an extensible PHP command-line tool for converting source content and metadata into packages suitable for importing into Islandora (or other digital repository and preservations systems).
GNU General Public License v3.0
34 stars 11 forks source link

Provide a MARC fetcher and metadata parser #141

Open mjordan opened 8 years ago

mjordan commented 8 years ago

http://pear.php.net/package/File_MARC (also available via composer) provides parsing of binary and XML MARC data. A minimalistic example of its use is:

<?php
require 'File/MARC.php';
$records = new File_MARC('binaryinpufile.mrc');
while ($record = $records->next()) {
     $resp = $record->getFields('245');
     $title = $resp[0]->getSubfields('a');
     print $title[0]->getData() . "\n";
}

MIK mappings could take the form

"245a","<titleInfo><title>How to migrate stuff</title></titleInfo>", etc.

MarcusBarnes commented 8 years ago

:thumbsup:

mjordan commented 8 years ago

In the composerized version:

<?php

require 'vendor/autoload.php';
use Scriptotek\Marc\Collection;

$collection = Collection::fromFile('input_file.mrc');
foreach ($collection->records as $record) {
  $field245a = $record->get('245$a');
  echo $field245a[0] ."\n";
}