Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub convertMARCtoXML
- {
- my $self = shift;
- my $marc = shift;
- print "headed into as_xml\n";
- my $thisXML = '';
- # Turn on dying from warnings
- # MARC::Charset can throw warnings here, and we don't want to continue if we get some
- local $SIG{__WARN__} = sub { die @_; };
- local $@;
- eval
- {
- $thisXML = $marc->as_xml();
- 1;
- } or do
- {
- $marc->encoding('UTF-8');
- $thisXML = $marc->as_xml();
- };
- # Turn off dying from warnings
- local $SIG{__WARN__} = sub { };
- $thisXML =~ s/\n//sog;
- $thisXML =~ s/^<\?xml.+\?\s*>//go;
- $thisXML =~ s/>\s+</></go;
- $thisXML =~ s/\p{Cc}//go;
- $thisXML = entityize($self, $thisXML);
- $thisXML =~ s/[\x00-\x1f]//go;
- $thisXML =~ s/^\s+//;
- $thisXML =~ s/\s+$//;
- $thisXML =~ s/<record><leader>/<leader>/;
- $thisXML =~ s/<collection/<record/;
- $thisXML =~ s/<\/record><\/collection>/<\/record>/;
- return $thisXML;
- }
- sub readMARCFile
- {
- my $self = shift;
- my $marcFile = shift;
- my $fExtension = getFileExt($self, $marcFile);
- my $file;
- $self->{log}->addLine("Reading $marcFile");
- $file = MARC::File::USMARC->in($marcFile) if $fExtension !=~ m/xml/;
- $file = MARC::File::XML->in($marcFile) if $fExtension =~ m/xml/;
- my @ret;
- local $@;
- eval
- {
- while ( my $marc = $file->next() )
- {
- if($marc->field('001')->data() eq 'EBC6178448')
- {
- print "adding EBC6178448\n";
- push (@ret, $marc);
- }
- }
- 1; # ok
- } or do
- {
- $file->close();
- @ret = @{readMARCFileRaw($self, $marcFile)};
- };
- $file->close();
- undef $file;
- return \@ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement