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
371
372
373
374
|
# File 'lib/marc/xml_parsers.rb', line 371
def self.extended(receiver)
require 'java' receiver.init
end
|
Instance Method Details
#attributes_to_hash(attributes) ⇒ Object
407
408
409
410
411
412
413
|
# File 'lib/marc/xml_parsers.rb', line 407
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
385
386
387
388
389
390
391
392
|
# File 'lib/marc/xml_parsers.rb', line 385
def each(&block)
unless block_given?
return self.enum_for(:each)
else
@block = block
parser_dispatch
end
end
|
#init ⇒ Object
376
377
378
379
380
381
382
|
# File 'lib/marc/xml_parsers.rb', line 376
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
394
395
396
397
398
399
400
401
402
403
404
405
|
# File 'lib/marc/xml_parsers.rb', line 394
def parser_dispatch
while event = @parser.next and event != javax.xml.stream.XMLStreamConstants.END_DOCUMENT do
case event
when javax.xml.stream.XMLStreamConstants.START_ELEMENT
start_element_namespace(@parser.getLocalName, [], nil, @parser.getNamespaceURI, nil)
when javax.xml.stream.XMLStreamConstants.END_ELEMENT
end_element_namespace(@parser.getLocalName, @parser.getPrefix, @parser.getNamespaceURI)
when javax.xml.stream.XMLStreamConstants.CHARACTERS
characters(@parser.getText)
end
end
end
|