class Libis::Ingester::Base::XmlParser
Attributes
callback[R]
Public Class Methods
new(document, callback = nil, &block)
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 9 def initialize(document, callback = nil, &block) @callback = callback || block raise WorkflowAbort, "XmlParser created without callback or block" unless @callback @char_buffer = '' File.open(document) do |f| Nokogiri::XML::SAX::Parser.new(self).parse(f) end end
Public Instance Methods
cdata_block(string)
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 44 def cdata_block(string) callback.call :cdata_block, string end
characters(string)
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 48 def characters(string) @char_buffer += string end
comment(string)
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 26 def comment(string) callback.call :comment, string end
end_document()
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 62 def end_document callback.call :end_document end
end_element(name)
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 52 def end_element(name) send_content callback.call :end_element, name end
end_element_namespace(name, prefix = nil, uri = nil)
click to toggle source
Calls superclass method
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 57 def end_element_namespace(name, prefix = nil, uri = nil) super callback.call :end_element_namespace, name, prefix, uri end
error(string)
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 66 def error(string) callback.call :error, string end
processing_instruction(name, content)
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 30 def processing_instruction(name, content) callback.call :processing_instruction, name, content end
start_document()
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 22 def start_document callback.call :start_document end
start_element(name, attrs = [])
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 34 def start_element(name, attrs = []) send_content callback.call :start_element, name, attrs end
start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = nil)
click to toggle source
Calls superclass method
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 39 def start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = nil) super callback.call :start_element_namespace, name, attrs, prefix, uri, ns end
warning(string)
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 70 def warning(string) callback.call :warning, string end
xmldecl(version, encoding, standalone)
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 18 def xmldecl(version, encoding, standalone) callback.call :xmldecl, version, encoding, standalone end
Protected Instance Methods
send_content()
click to toggle source
# File lib/libis/ingester/tasks/base/xml_parser.rb, line 76 def send_content @char_buffer.strip! callback.call :characters, @char_buffer unless @char_buffer.empty? @char_buffer = '' end