Module: MARC::REXMLReader
- Defined in:
- lib/marc/xml_parsers.rb
Overview
The REXMLReader is the ‘default’ parser, since we can at least be assured that REXML is probably there. It uses REXML’s PullParser to handle larger document sizes without consuming insane amounts of memory, but it’s still REXML (read: slow), so it’s a good idea to use an alternative parser if available. If you don’t know the best parser available, you can use the MagicReader or set:
MARC::XMLReader.parser=MARC::XMLReader::USE_BEST_AVAILABLE
or
MARC::XMLReader.parser=“magic”
or
reader = MARC::XMLReader.new(fh, :parser=>“magic”) (or the constant)
which will cascade down to REXML if nothing better is found.
Class Method Summary collapse
Instance Method Summary collapse
-
#each ⇒ Object
Loop through the MARC records in the XML document.
-
#init ⇒ Object
Sets our parser.
Class Method Details
.extended(receiver) ⇒ Object
167 168 169 170 171 |
# File 'lib/marc/xml_parsers.rb', line 167 def self.extended(receiver) require 'rexml/document' require 'rexml/parsers/pullparser' receiver.init end |
Instance Method Details
#each ⇒ Object
Loop through the MARC records in the XML document
179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/marc/xml_parsers.rb', line 179 def each unless block_given? return self.enum_for(:each) else while @parser.has_next? event = @parser.pull # if it's the start of a record element if event.start_element? and strip_ns(event[0]) == 'record' yield build_record end end end end |
#init ⇒ Object
Sets our parser
174 175 176 |
# File 'lib/marc/xml_parsers.rb', line 174 def init @parser = REXML::Parsers::PullParser.new(@handle) end |