C4::Record - MARC, MARCXML, DC, MODS, XML, etc. Record Management Functions and API


New in Koha 3.x. This module handles all record-related management functions.


marc2marc - Convert from one flavour of ISO-2709 to another

my ($error,$newmarc) = marc2marc($marc,$to_flavour,$from_flavour,$encoding);

Returns an ISO-2709 scalar

marc2marcxml - Convert from ISO-2709 to MARCXML

my ($error,$marcxml) = marc2marcxml($marc,$encoding,$flavour);

Returns a MARCXML scalar

$marc - an ISO-2709 scalar or MARC::Record object

$encoding - UTF-8 or MARC-8 [UTF-8]

$flavour - MARC21 or UNIMARC

$dont_entity_encode - a flag that instructs marc2marcxml not to entity encode the xml before returning (optional)

marcxml2marc - Convert from MARCXML to ISO-2709

my ($error,$marc) = marcxml2marc($marcxml,$encoding,$flavour);

Returns an ISO-2709 scalar

$marcxml - a MARCXML record

$encoding - UTF-8 or MARC-8 [UTF-8]

$flavour - MARC21 or UNIMARC

marc2dcxml - Convert from ISO-2709 to Dublin Core

my ($error,$dcxml) = marc2dcxml($marc,$qualified);

Returns a DublinCore::Record object, will eventually return a Dublin Core scalar

FIXME: should return actual XML, not just an object

$marc - an ISO-2709 scalar or MARC::Record object

$qualified - specify whether qualified Dublin Core should be used in the input or output [0]

marc2modsxml - Convert from ISO-2709 to MODS

my ($error,$modsxml) = marc2modsxml($marc);

Returns a MODS scalar

marc2csv - Convert several records from UNIMARC to CSV Pre and postprocessing can be done through a YAML file

my ($csv) = marc2csv($biblios, $csvprofileid);

Returns a CSV scalar

$biblio - a list of biblionumbers

$csvprofileid - the id of the CSV profile to use for the export (see export_format.export_format_id and the GetCsvProfiles function in C4::Csv)

marcrecord2csv - Convert a single record from UNIMARC to CSV

my ($csv) = marcrecord2csv($biblio, $csvprofileid, $header);

Returns a CSV scalar

$biblio - a biblionumber

$csvprofileid - the id of the CSV profile to use for the export (see export_format.export_format_id and the GetCsvProfiles function in C4::Csv)

$header - true if the headers are to be printed (typically at first pass)

$csv - an already initialised Text::CSV object


my ($error,$marcxml) = html2marcxml($tags,$subfields,$values,$indicator,$ind_tag);

Returns a MARCXML scalar

this is used in addbiblio.pl and additem.pl to build the MARCXML record from the form submission.

FIXME: this could use some better code documentation


Probably best to avoid using this ... it has some rather striking problems:

* saves blank subfields

* subfield order is hardcoded to always start with 'a' for repeatable tags (because it is hardcoded in the addfield routine).

* only possible to specify one set of indicators for each set of tags (ie, one for all the 650s). (because they were stored in a hash with the tag as the key).

* the underlying routines didn't support subfield reordering or subfield repeatability.

I've left it in here because it could be useful if someone took the time to fix it. -- kados

changeEncoding - Change the encoding of a record

my ($error, $newrecord) = changeEncoding($record,$format,$flavour,$to_encoding,$from_encoding);

Changes the encoding of a record

$record - the record itself can be in ISO-2709, a MARC::Record object, or MARCXML for now (required)

$format - MARC or MARCXML (required)

$flavour - MARC21 or UNIMARC, if MARC21, it will change the leader (optional) [defaults to Koha system preference]

$to_encoding - the encoding you want the record to end up in (optional) [UTF-8]

$from_encoding - the encoding the record is currently in (optional, it will probably be able to tell unless there's a problem with the record)

FIXME: the from_encoding doesn't work yet

FIXME: better handling for UNIMARC, it should allow management of 100 field

FIXME: shouldn't have to convert to and from xml/marc just to change encoding someone needs to re-write MARC::Record's 'encoding' method to actually alter the encoding rather than just changing the leader

marc2bibtex - Convert from MARC21 and UNIMARC to BibTex

my ($bibtex) = marc2bibtex($record, $id);

Returns a BibTex scalar

$record - a MARC::Record object

$id - an id for the BibTex record (might be the biblionumber)


_entity_encode - Entity-encode an array of strings

my ($entity_encoded_string) = _entity_encode($string);


my (@entity_encoded_strings) = _entity_encode(@strings);

Entity-encode an array of strings


Joshua Ferraro <jmf@liblime.com>