From 75f4e815337df2cc1909af436f0979a254bb17aa Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 24 Sep 2014 00:19:58 +0200 Subject: [PATCH] Use namespace_name in Attribute#to_xml Instead of using `namespace.name` lets just use `namespace_name`. This fixes the problem of serializing attributes where the namespace prefix is "xmlns" as the namespace for this isn't registered by default. This fixes #47. --- lib/oga/xml/attribute.rb | 2 +- spec/oga/xml/attribute_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/oga/xml/attribute.rb b/lib/oga/xml/attribute.rb index 7b00ad1..cbe2821 100644 --- a/lib/oga/xml/attribute.rb +++ b/lib/oga/xml/attribute.rb @@ -82,7 +82,7 @@ module Oga # def to_xml if namespace_name - full_name = "#{namespace.name}:#{name}" + full_name = "#{namespace_name}:#{name}" else full_name = name end diff --git a/spec/oga/xml/attribute_spec.rb b/spec/oga/xml/attribute_spec.rb index 737b7f2..23e1e4f 100644 --- a/spec/oga/xml/attribute_spec.rb +++ b/spec/oga/xml/attribute_spec.rb @@ -68,6 +68,16 @@ describe Oga::XML::Attribute do attr.to_xml.should == 'foo:class="10"' end + + example 'include the "xmlns" namespace when present but not registered' do + attr = described_class.new( + :name => 'class', + :namespace_name => 'xmlns', + :element => Oga::XML::Element.new + ) + + attr.to_xml.should == 'xmlns:class=""' + end end context '#inspect' do