lib/niceogiri/xml/node.rb in niceogiri-1.0.2 vs lib/niceogiri/xml/node.rb in niceogiri-1.1.0

- old
+ new

@@ -30,12 +30,12 @@ # Helper method to write a value to an attribute # # @param [#to_sym] attr_name the name of the attribute # @param [#to_s] value the value to set the attribute to - def write_attr(attr_name, value) - self[attr_name.to_sym] = value + def write_attr(attr_name, value, to_call = nil) + self[attr_name.to_sym] = value && to_call ? value.__send__(to_call) : value end # Helper method to read the content of a node # # @param [#to_sym] node the name of the node @@ -131,12 +131,18 @@ # Inherit the attributes and children of an XML::Node # # @param [XML::Node] node the node to inherit # @return [self] def inherit(node) - nokogiri_namespace = node.namespace + self.namespace = node.namespace.href if node.namespace inherit_attrs node.attributes - node.children.each { |c| self << c.dup } + node.children.each do |c| + self << (n = c.dup) + if c.respond_to?(:namespace) && c.namespace + ns = n.add_namespace c.namespace.prefix, c.namespace.href + n.namespace = ns + end + end self end # Inherit a set of attributes #