diff --git a/lib/oga/xml/element.rb b/lib/oga/xml/element.rb
index cde3ff9..8980fc2 100644
--- a/lib/oga/xml/element.rb
+++ b/lib/oga/xml/element.rb
@@ -211,11 +211,9 @@ module Oga
attrs = ''
attributes.each do |attr|
- attrs << attr.to_xml
+ attrs << " #{attr.to_xml}"
end
- attrs = " #{attrs}" unless attrs.empty?
-
return "<#{ns}#{name}#{attrs}>#{body}#{ns}#{name}>"
end
diff --git a/spec/oga/xml/element_spec.rb b/spec/oga/xml/element_spec.rb
index 047c606..88d8716 100644
--- a/spec/oga/xml/element_spec.rb
+++ b/spec/oga/xml/element_spec.rb
@@ -261,7 +261,7 @@ describe Oga::XML::Element do
instance.to_xml.should == '