class MARC::XMLReader

the constructor which you can pass either a filename:

reader = MARC::XMLReader.new('/Users/edsu/marc.xml')

or a File object,

reader = Marc::XMLReader.new(File.new('/Users/edsu/marc.xml'))

or really any object that responds to read(n)

reader = MARC::XMLReader.new(StringIO.new(xml))

By default, XMLReader uses REXML’s pull parser, but you can swap that out with Nokogiri or jrexml (or let the system choose the ‘best’ one). The :parser can either be one of the defined constants or the constant’s value.

reader = MARC::XMLReader.new(fh, :parser=>'magic')

It is also possible to set the default parser at the class level so all subsequent instances will use it instead:

MARC::XMLReader.best_available
"nokogiri" # returns parser name, but doesn't set it.

Use:

MARC::XMLReader.best_available!

or

MARC::XMLReader.nokogiri!

By default, all XML parsers except REXML require the MARC namespace (www.loc.gov/MARC21/slim) to be included. Adding the option ‘ignore_namespace` to the call to `new` with a true value will allow parsing to proceed, e.g.,

reader = MARC::XMLReader.new(filename, parser: :nokogiri, ignore_namespace: true)

You can also pass in an error_handler option that will be called if there are any validation errors found when parsing a record.

reader = MARC::XMLReader.new(fh, error_handler: ->(reader, record, block) { ... })

By default, a MARC::RecordException is raised halting all future parsing.