org.marc4j
Class MarcXmlReader

java.lang.Object
  extended by org.marc4j.MarcXmlReader
All Implemented Interfaces:
MarcReader

public class MarcXmlReader
extends Object
implements MarcReader

An iterator over a collection of MARC records in MARCXML format.

Basic usage:

 InputStream input = new FileInputStream("file.xml");
 MarcReader reader = new MarcXmlReader(input);
 while (reader.hasNext()) {
   Record record = reader.next();
   // Process record
 }
 

Check the org.marc4j.marc package for examples about the use of the Record object model.

You can also pre-process the source to create MARC XML from a different format using an XSLT stylesheet. The following example creates an iterator over a collection of MARC records in MARC XML format from a MODS source and outputs MARC records in MARC21 format:

 InputStream in = new FileInputStream("modsfile.xml");
 
 MarcStreamWriter writer = new MarcStreamWriter(System.out, Constants.MARC8);
 MarcXmlReader reader = new MarcXmlReader(in, "http://www.loc.gov/standards/marcxml/xslt/MODS2MARC21slim.xsl");
 while (reader.hasNext()) {
   Record record = reader.next();
   writer.write(record);
 }
 writer.close();
 

Version:
$Revision: 1.4 $
Author:
Bas Peters

Constructor Summary
MarcXmlReader(InputSource input)
          Constructs an instance with the specified input source.
MarcXmlReader(InputSource input, Source stylesheet)
          Constructs an instance with the specified input source and stylesheet source.
MarcXmlReader(InputSource input, TransformerHandler th)
          Constructs an instance with the specified input source and transformer handler.
MarcXmlReader(InputStream input)
          Constructs an instance with the specified input stream.
MarcXmlReader(InputStream input, Source stylesheet)
          Constructs an instance with the specified input stream and stylesheet source.
MarcXmlReader(InputStream input, String stylesheetUrl)
          Constructs an instance with the specified input stream and stylesheet location.
MarcXmlReader(InputStream input, TransformerHandler th)
          Constructs an instance with the specified input stream and transformer handler.
 
Method Summary
 boolean hasNext()
          Returns true if the iteration has more records, false otherwise.
 Record next()
          Returns the next record in the iteration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MarcXmlReader

public MarcXmlReader(InputStream input)
Constructs an instance with the specified input stream.

Parameters:
input - the input stream

MarcXmlReader

public MarcXmlReader(InputSource input)
Constructs an instance with the specified input source.

Parameters:
input - the input source

MarcXmlReader

public MarcXmlReader(InputStream input,
                     String stylesheetUrl)
Constructs an instance with the specified input stream and stylesheet location. The stylesheet is used to transform the source file and should produce valid MARC XML records. The result is then used to create Record objects.

Parameters:
input - the input stream
stylesheetUrl - the stylesheet location

MarcXmlReader

public MarcXmlReader(InputStream input,
                     Source stylesheet)
Constructs an instance with the specified input stream and stylesheet source. The stylesheet is used to transform the source file and should produce valid MARCXML records. The result is then used to create Record objects.

Parameters:
input - the input stream
stylesheet - the stylesheet source

MarcXmlReader

public MarcXmlReader(InputSource input,
                     Source stylesheet)
Constructs an instance with the specified input source and stylesheet source. The stylesheet is used to transform the source file and should produce valid MARCXML records. The result is then used to create Record objects.

Parameters:
input - the input source
stylesheet - the stylesheet source

MarcXmlReader

public MarcXmlReader(InputStream input,
                     TransformerHandler th)
Constructs an instance with the specified input stream and transformer handler. The TransformerHandler is used to transform the source file and should produce valid MARCXML records. The result is then used to create Record objects. A TransformerHandler can be obtained from a SAXTransformerFactory with either a Source or Templates object.

Parameters:
input - the input stream
th - the transformation content handler

MarcXmlReader

public MarcXmlReader(InputSource input,
                     TransformerHandler th)
Constructs an instance with the specified input source and transformer handler. The TransformerHandler is used to transform the source file and should produce valid MARCXML records. The result is then used to create Record objects. A TransformerHandler can be obtained from a SAXTransformerFactory with either a Source or Templates object.

Parameters:
input - the input source
th - the transformation content handler
Method Detail

hasNext

public boolean hasNext()
Returns true if the iteration has more records, false otherwise.

Specified by:
hasNext in interface MarcReader
Returns:
boolean - true if the iteration has more records, false otherwise

next

public Record next()
Returns the next record in the iteration.

Specified by:
next in interface MarcReader
Returns:
Record - the record object


Copyright © 2002-2006 Bas Peters. All Rights Reserved.