Advertisement
Guest User

Untitled

a guest
Mar 14th, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1.  
  2. sub convertMARCtoXML
  3. {
  4. my $self = shift;
  5. my $marc = shift;
  6. print "headed into as_xml\n";
  7. my $thisXML = '';
  8. # Turn on dying from warnings
  9. # MARC::Charset can throw warnings here, and we don't want to continue if we get some
  10. local $SIG{__WARN__} = sub { die @_; };
  11. local $@;
  12. eval
  13. {
  14. $thisXML = $marc->as_xml();
  15. 1;
  16. } or do
  17. {
  18. $marc->encoding('UTF-8');
  19. $thisXML = $marc->as_xml();
  20. };
  21.  
  22. # Turn off dying from warnings
  23. local $SIG{__WARN__} = sub { };
  24.  
  25. $thisXML =~ s/\n//sog;
  26. $thisXML =~ s/^<\?xml.+\?\s*>//go;
  27. $thisXML =~ s/>\s+</></go;
  28. $thisXML =~ s/\p{Cc}//go;
  29. $thisXML = entityize($self, $thisXML);
  30. $thisXML =~ s/[\x00-\x1f]//go;
  31. $thisXML =~ s/^\s+//;
  32. $thisXML =~ s/\s+$//;
  33. $thisXML =~ s/<record><leader>/<leader>/;
  34. $thisXML =~ s/<collection/<record/;
  35. $thisXML =~ s/<\/record><\/collection>/<\/record>/;
  36.  
  37. return $thisXML;
  38. }
  39.  
  40.  
  41.  
  42. sub readMARCFile
  43. {
  44. my $self = shift;
  45. my $marcFile = shift;
  46. my $fExtension = getFileExt($self, $marcFile);
  47. my $file;
  48. $self->{log}->addLine("Reading $marcFile");
  49. $file = MARC::File::USMARC->in($marcFile) if $fExtension !=~ m/xml/;
  50. $file = MARC::File::XML->in($marcFile) if $fExtension =~ m/xml/;
  51. my @ret;
  52. local $@;
  53. eval
  54. {
  55. while ( my $marc = $file->next() )
  56. {
  57. if($marc->field('001')->data() eq 'EBC6178448')
  58. {
  59. print "adding EBC6178448\n";
  60. push (@ret, $marc);
  61. }
  62. }
  63. 1; # ok
  64. } or do
  65. {
  66. $file->close();
  67. @ret = @{readMARCFileRaw($self, $marcFile)};
  68. };
  69.  
  70. $file->close();
  71. undef $file;
  72. return \@ret;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement