/usr/share/perl5/Catmandu/Importer/SRU/Parser/marcxml.pm is in libcatmandu-sru-perl 0.039-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | =head1 NAME
Catmandu::Importer::SRU::Parser::marcxml - Package transforms SRU responses into Catmandu MARC
=head1 SYNOPSIS
my %attrs = (
base => 'http://www.unicat.be/sru',
query => '(isbn=0855275103 or isbn=3110035170 or isbn=9010017362 or isbn=9014026188)',
recordSchema => 'marcxml' ,
parser => 'marcxml' ,
);
my $importer = Catmandu::Importer::SRU->new(%attrs);
=head1 DESCRIPTION
Each MARCXML response will be transformed into an format as defined by L<Catmandu::Importer::MARC>
=head1 AUTHOR
Patrick Hochstenbach, C<< <patrick.hochstenbach at ugent.be> >>
=cut
package Catmandu::Importer::SRU::Parser::marcxml;
use Moo;
use XML::LibXML;
sub parse {
my ($self,$record) = @_;
my $xml = $record->{recordData};
my $parser = XML::LibXML->new();
my $doc = $parser->parse_string($xml);
my $root = $doc->documentElement;
my @out;
my $id = undef;
for my $field ($root->getChildrenByLocalName('*')) {
my $name = $field->localname;
my $value = $field->textContent // '';
if ($name eq 'leader') {
push @out, [ 'LDR', ' ', ' ', '_', $value ];
}
elsif ($name eq 'controlfield') {
my $tag = $field->getAttribute( 'tag' );
push @out, [ $tag, ' ', ' ', '_', $value ];
$id = $value if $tag eq '001';
}
elsif ( $name eq 'datafield' ) {
my $tag = $field->getAttribute( 'tag' );
my $ind1 = $field->getAttribute( 'ind1' ) // ' ';
my $ind2 = $field->getAttribute( 'ind2' ) // ' ';
my @subfield = ();
for my $subfield ( $field->getChildrenByLocalName('subfield') ) {
my $code = $subfield->getAttribute( 'code' );
my $value = $subfield->textContent;
push @subfield, $code, $value;
}
push @out, [ $tag, $ind1, $ind2, @subfield ];
}
}
return { _id => $id , record => \@out };
}
1;
|