Advertisement
Guest User

Untitled

a guest
Mar 14th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.88 KB | None | 0 0
  1.  
  2. sub convertMARCtoXML
  3. {
  4.     my $self = shift;
  5.     my $marc = shift;
  6.  
  7.     my $thisXML = '';
  8.     local $@;
  9.     eval
  10.     {
  11.         # Turn on dying from warnings
  12.         # MARC::Charset can throw warnings here, and we don't want to continue if we get some
  13.         local $SIG{__WARN__} = sub { die @_; };
  14.         $thisXML = $marc->as_xml();
  15.         1;
  16.     } or do
  17.     {
  18.         $marc->encoding('UTF-8');
  19.         $thisXML = $marc->as_xml();
  20.     };
  21.  
  22.     $thisXML =~ s/\n//sog;
  23.     $thisXML =~ s/^<\?xml.+\?\s*>//go;
  24.     $thisXML =~ s/>\s+</></go;
  25.     $thisXML =~ s/\p{Cc}//go;
  26.     $thisXML = entityize($self, $thisXML);
  27.     $thisXML =~ s/[\x00-\x1f]//go;
  28.     $thisXML =~ s/^\s+//;
  29.     $thisXML =~ s/\s+$//;
  30.     $thisXML =~ s/<record><leader>/<leader>/;
  31.     $thisXML =~ s/<collection/<record/;
  32.     $thisXML =~ s/<\/record><\/collection>/<\/record>/;
  33.  
  34.     return $thisXML;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement