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.
This commit is contained in:
Yorick Peterse 2014-09-15 21:42:08 +02:00
parent 1abba1be9c
commit 795e669632
2 changed files with 11 additions and 1 deletions

View File

@ -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 = ''

View File

@ -315,6 +315,16 @@ describe Oga::XML::Element do
instance.to_xml.should == '<p><!--foo--></p>'
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 == '<foo></foo>'
end
end
context '#inspect' do