MARC4J provides an easy to use API for working with MARC (binary), MARCXML, MARC JSON in Java. MARC stands for MAchine Readable Cataloging and is a widely used exchange format for bibliographic data. MARCXML provides a loss-less conversion between MARC (MARC21 but also other formats like UNIMARC) and XML.
Features
The MARC4J library includes:
...
- Leader leader;
- List<ControlField> controlFields
- List<DataField> dataFields
- List<MarcError> errors
Marc4j lib testing experience
Types
For testing this library we use all types of marc records. This records you can found here.
Types of records were tested:
- MARC Authority
- MARC Bibliographic
- MARC Holdings
- Mixed MARC Bib+Hld
Marc4j successfully parsed all types and convert them into the list of internal Record entities. For mixed records it works fine, but we can not select from the parsed list the necessary records by its type. It is possible only by analyzing record's fields.
Encoding and formats
During testing marc4j lib we use record with next formats:
- XML
- Binary *.mrc files
Binary records was encoded:
- UTF-8
- MARC 8
During parsing records, marc4j decode all data from records into UTF-8 format. It work nice for all types and encodings and it understand non latin symbols. After parsing, the data in the list of records is stored in UTF-8 encoding.Â
ExamplesÂ
Source record
LEADER 00508cjm a22001813 4500
001 10062588
005 20171013073237.0
007 sd fsngnnmmneu
008 170825s2017 xx nn n zxx d
024 7 $a00190295755553$2gtin-14
024 1 $a190295755553
035 $a(OCoLC)1002130878
035 $a10062588
040 $aBTCTA$beng$cBTCTA
100 1 $aRossi, Daniele
245 00$aSaint-Saens: Organ Symphony and Carnival of The Animals
260 $bWea Corp$c2017.
948 2 $a20171013$bm$dbatch$elts$xdeloclcprefix
JSONÂ representation of marc record entity
{
"leader": "00508cjm a22001813 4500",
"fields": [
{
"001": "10062588"
},
{
"005": "20171013073237.0"
},
{
"007": "sd fsngnnmmneu"
},
{
"008": "170825s2017 xx nn n zxx d"
},
{
"024": {
"subfields": [
{
"a": "00190295755553"
},
{
"2": "gtin-14"
}
],
"ind1": "7",
"ind2": " "
}
},
{
"024": {
"subfields": [
{
"a": "190295755553"
}
],
"ind1": "1",
"ind2": " "
}
},
{
"035": {
"subfields": [
{
"a": "(OCoLC)1002130878"
}
],
"ind1": " ",
"ind2": " "
}
},
{
"035": {
"subfields": [
{
"a": "10062588"
}
],
"ind1": " ",
"ind2": " "
}
},
{
"040": {
"subfields": [
{
"a": "BTCTA"
},
{
"b": "eng"
},
{
"c": "BTCTA"
}
],
"ind1": " ",
"ind2": " "
}
},
{
"100": {
"subfields": [
{
"a": "Rossi, Daniele"
}
],
"ind1": "1",
"ind2": " "
}
},
{
"245": {
"subfields": [
{
"a": "Saint-Saens: Organ Symphony and Carnival of The Animals"
}
],
"ind1": "0",
"ind2": "0"
}
},
{
"260": {
"subfields": [
{
"b": "Wea Corp"
},
{
"c": "2017."
}
],
"ind1": " ",
"ind2": " "
}
},
{
"948": {
"subfields": [
{
"a": "20171013"
},
{
"b": "m"
},
{
"d": "batch"
},
{
"e": "lts"
},
{
"x": "deloclcprefix"
}
],
"ind1": "2",
"ind2": " "
}
}
]
}
Code snippet
to parse MARC file and print all information to console
public class App {
public static void main(String args[]) throws Exception {
// path to .mrc file
String path = "";
// Input Stream from file
InputStream in = new FileInputStream(path);
MarcReader reader = new MarcStreamReader(in);
while (reader.hasNext()) {
Record record = reader.next();
Leader leader = record.getLeader();
List<ControlField> controlFields = record.getControlFields();
List<DataField> dataFields = record.getDataFields();
System.out.println();
System.out.println("LEADER: " + leader);
System.out.println("Control fields: ");
controlFields.forEach(System.out::println);
System.out.println("Data fields: ");
dataFields.forEach(System.out::println);
System.out.println();
}
}
}