MARC4J provide an easy to use API for working with MARC, 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:
...
Although MARC4J is primarily designed for Java development you can use the command-line utilities org.marc4j.util.MarcXmlDriver
and org.marc4j.util.XmlMarcDriver
to convert between MARC and MARCXML. It is also possible to pre- or postprocess the result using XSLT, for example to convert directly from MODS to MARC or from MARC to MODS.
Parsing records
For parse records and interact with them you need to use to main Interfaces:
...
Code snippet on Java 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();
}
}
}