Module: MARC::JRubySTAXReader
Class Method Summary
collapse
Instance Method Summary
collapse
#characters, #end_element_namespace, #start_element_namespace, #yield_record
Class Method Details
.extended(receiver) ⇒ Object
354
355
356
357
358
359
|
# File 'lib/marc/xml_parsers.rb', line 354
def self.extended(receiver)
include Java
java.lang.Class.forName("javax.xml.stream.XMLInputFactory")
include javax.xml.stream
receiver.init
end
|
Instance Method Details
#attributes_to_hash(attributes) ⇒ Object
388
389
390
391
392
393
394
|
# File 'lib/marc/xml_parsers.rb', line 388
def attributes_to_hash(attributes)
hash = {}
@parser.getAttributeCount.times do | i |
hash[@parser.getAttributeName(i).getLocalPart] = @parser.getAttributeValue(i)
end
hash
end
|
#each(&block) ⇒ Object
Loop through the MARC records in the XML document
370
371
372
373
|
# File 'lib/marc/xml_parsers.rb', line 370
def each(&block)
@block = block
parser_dispatch
end
|
#init ⇒ Object
361
362
363
364
365
366
367
|
# File 'lib/marc/xml_parsers.rb', line 361
def init
@record = {:record=>nil,:field=>nil,:subfield=>nil}
@current_element = nil
@ns = "http://www.loc.gov/MARC21/slim"
@factory = javax.xml.stream.XMLInputFactory.newInstance
@parser = @factory.createXMLStreamReader(@handle.to_inputstream)
end
|
#parser_dispatch ⇒ Object
375
376
377
378
379
380
381
382
383
384
385
386
|
# File 'lib/marc/xml_parsers.rb', line 375
def parser_dispatch
while event = @parser.next and event != XMLStreamConstants.END_DOCUMENT do
case event
when XMLStreamConstants.START_ELEMENT
start_element_namespace(@parser.getLocalName, [], nil, @parser.getNamespaceURI, nil)
when XMLStreamConstants.END_ELEMENT
end_element_namespace(@parser.getLocalName, @parser.getPrefix, @parser.getNamespaceURI)
when XMLStreamConstants.CHARACTERS
characters(@parser.getText)
end
end
end
|