lib/xommelier/xml/element/serialization.rb in xommelier-0.1.3 vs lib/xommelier/xml/element/serialization.rb in xommelier-0.1.4

- old
+ new

@@ -82,11 +82,11 @@ serialize_attribute(name, value, attribute_values) end (prefix ? builder[prefix] : builder). send(element_name, attribute_values) do |xml| elements.each do |name, value| - serialize_element(name, value, xml) + serialize_element(name, value, xml, self.class.elements[name].merge(parent_ns_prefix: prefix)) end if respond_to?(:text) xml.text @text end end @@ -144,21 +144,25 @@ else type.from_xommelier(node.text) end end - def serialize_element(name, value, xml, options = nil) - options ||= self.element_options(name) + def serialize_element(name, value, xml, options = {}) + prefix = if options[:ns].try(:!=, xmlns) + xml.doc.namespaces.key(options[:ns].uri)[6..-1].presence + else + nil + end case options[:count] when :any, :many single_element = options.merge(count: :one) value.each { |item| serialize_element(name, item, xml, single_element) } else case value when Xommelier::Xml::Element value.to_xommelier(builder: xml, element_name: options[:element_name]) else - xml.send(options[:element_name]) { xml.text value.to_xommelier } + (prefix ? xml[prefix] : xml).send(options[:element_name]) { xml.text value.to_xommelier } end end end end end