lib/sax-machine/sax_handler.rb in astro-sax-machine-0.0.14 vs lib/sax-machine/sax_handler.rb in astro-sax-machine-0.0.15
- old
+ new
@@ -1,14 +1,15 @@
require "nokogiri"
+require "sax-machine/ns_stack"
module SAXMachine
class SAXHandler < Nokogiri::XML::SAX::Document
attr_reader :object
def initialize(object)
@object = object
- @parsed_configs = {}
+ @nsstack = nil
end
def characters(string)
if parsing_collection?
@collection_handler.characters(string)
@@ -23,10 +24,11 @@
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)
@@ -49,15 +51,15 @@
elsif parsing_collection?
@collection_handler.end_element(name)
elsif characaters_captured?
- mark_as_parsed
@object.send(@element_config.setter, @value)
end
reset_current_tag
+ @nsstack = @nsstack.pop
end
def characaters_captured?
!@value.nil? && !@value.empty?
end
@@ -73,33 +75,20 @@
end
end
def parse_element_attributes(element_configs)
element_configs.each do |ec|
- unless parsed_config?(ec)
- @object.send(ec.setter, ec.value_from_attrs(@attrs))
- mark_as_parsed(ec)
- end
+ @object.send(ec.setter, ec.value_from_attrs(@attrs))
end
@element_config = nil
end
def set_element_config_for_element_value
@value = ""
- @element_config = sax_config.element_config_for_tag(@name, @attrs)
+ @element_config = sax_config.element_config_for_tag(@name, @attrs, @nsstack)
end
- def mark_as_parsed(element_config=nil)
- element_config ||= @element_config
- @parsed_configs[element_config] = true unless element_config.collection?
- end
-
- def parsed_config?(element_config=nil)
- element_config ||= @element_config
- @parsed_configs[element_config]
- end
-
def reset_current_collection
@collection_handler = nil
@collection_config = nil
end
@@ -127,6 +116,6 @@
string.gsub(/&#{key};/, entities[key])
}
end
end
-end
\ No newline at end of file
+end