From 795e669632b06b956cb7ea1099611e4bedd6726d Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 15 Sep 2014 21:42:08 +0200 Subject: [PATCH] Ignore default NS when serializing elements. When a default namespace is set (using xmlns="...") the method XML::Element#to_xml should _not_ include the namespace prefix in the output. --- lib/oga/xml/element.rb | 2 +- spec/oga/xml/element_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/oga/xml/element.rb b/lib/oga/xml/element.rb index 2a91bcd..6126867 100644 --- a/lib/oga/xml/element.rb +++ b/lib/oga/xml/element.rb @@ -211,7 +211,7 @@ module Oga # @return [String] # def to_xml - ns = namespace ? "#{namespace}:" : '' + ns = namespace_name ? "#{namespace_name}:" : '' body = children.map(&:to_xml).join('') attrs = '' diff --git a/spec/oga/xml/element_spec.rb b/spec/oga/xml/element_spec.rb index 416e4a0..6723654 100644 --- a/spec/oga/xml/element_spec.rb +++ b/spec/oga/xml/element_spec.rb @@ -315,6 +315,16 @@ describe Oga::XML::Element do instance.to_xml.should == '

' end + + example 'generate the corresponding XML when using a default namespace' do + namespace = Oga::XML::Namespace.new(:name => 'xmlns', :uri => 'foo') + instance = described_class.new( + :name => 'foo', + :namespaces => {'xmlns' => namespace} + ) + + instance.to_xml.should == '' + end end context '#inspect' do