21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/xml_dsl/extensions.rb', line 21
def iterate(xml_obj = nil, acc: nil, &block)
xml_obj ||= xml
raise ArgumentError, "If there is no @xml in parser, pass it to iterate" if xml_obj.nil?
xml_obj.search(_xml_root_path).each do |node|
begin
instance = _xml_target_class.new
_xml_parse_callbacks[:readers].each do |bm|
bm.call instance, node, self
end
yield instance if block_given?
acc << instance if acc
rescue XmlDsl::ParseError => e
_xml_parse_callbacks[:error_handlers].each do |bm|
bm.call e, node, self
end
end
end
acc
end
|