From d32d5cb98351066f0f6d6259f042803dc62cf127 Mon Sep 17 00:00:00 2001
From: miker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Tue, 16 Mar 2010 14:16:52 +0000
Subject: [PATCH] Patch from Galen Charlton: removes empty controlfield
 elements, which can be produced in a couple different ways during the ingest
 of slightly invalid MARC records

git-svn-id: svn://svn.open-ils.org/ILS/trunk@15858 dcc99617-32d9-48b4-a31d-7c20da2025e4
---
 Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm b/Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm
index dc06a9c067..1b1fbae4d1 100644
--- a/Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm
+++ b/Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm
@@ -111,6 +111,11 @@ sub __make_marc_doc {
 	my $marcxml = XML::LibXML->new->parse_string($xml);
 	$marcxml->documentElement->setNamespace($MARC_NAMESPACE, "marc", 1 );
 	$marcxml->documentElement->setNamespace($MARC_NAMESPACE);
+	# remove empty control fields - at least one source of records adds ersatz blank 008s
+	# that become empty controlfield elements
+	foreach my $controlfield ($marcxml->documentElement->getElementsByTagNameNS($MARC_NAMESPACE, 'controlfield')) {
+		$controlfield->parentNode->removeChild($controlfield) unless $controlfield->hasChildNodes();
+	}
 	return $marcxml;
 }
 
-- 
2.11.0