lib/sax-machine/sax_handler.rb in astro-sax-machine-0.0.15 vs lib/sax-machine/sax_handler.rb in astro-sax-machine-0.0.16

- old
+ new

@@ -3,13 +3,13 @@ module SAXMachine class SAXHandler < Nokogiri::XML::SAX::Document attr_reader :object - def initialize(object) + def initialize(object, nsstack=nil) @object = object - @nsstack = nil + @nsstack = nsstack || NSStack.new end def characters(string) if parsing_collection? @collection_handler.characters(string) @@ -21,20 +21,20 @@ def cdata_block(string) characters(string) end def start_element(name, attrs = []) - + @name = name @attrs = attrs.map { |a| SAXHandler.decode_xml(a) } @nsstack = NSStack.new(@nsstack, @attrs) if parsing_collection? @collection_handler.start_element(@name, @attrs) - elsif @collection_config = sax_config.collection_config(@name) - @collection_handler = @collection_config.handler + elsif @collection_config = sax_config.collection_config(@name, @nsstack) + @collection_handler = @collection_config.handler(@nsstack) @collection_handler.start_element(@name, @attrs) elsif (element_configs = sax_config.element_configs_for_attribute(@name, @attrs)).any? parse_element_attributes(element_configs) set_element_config_for_element_value @@ -44,9 +44,10 @@ end end def end_element(name) if parsing_collection? && @collection_config.name == name + @collection_handler.end_element(name) @object.send(@collection_config.accessor) << @collection_handler.object reset_current_collection elsif parsing_collection? @collection_handler.end_element(name)