Fix for ticket #138
3 files changed, 13 insertions(+), 2 deletions(-)

M src/rexml/element.rb
M src/rexml/formatters/default.rb
M test/core_test.rb
M src/rexml/element.rb +3 -1
@@ 990,7 990,9 @@ module REXML
     end
 
     def to_a
-      values.flatten
+      attributes = []
+      each_attribute {|attr| attributes << attr}
+      attributes
     end
 
     # Returns the number of attributes the owning Element contains.

          
M src/rexml/formatters/default.rb +1 -1
@@ 63,7 63,7 @@ module REXML
       def write_element( node, output )
         output << "<#{node.expanded_name}"
 
-        node.attributes.to_a.sort_by {|attr| attr.name}.each do |attr|
+        node.attributes.to_a.sort_by {|attr| attr.expanded_name}.each do |attr|
           output << " "
           attr.write( output )
         end unless node.attributes.empty?

          
M test/core_test.rb +9 -0
@@ 1349,6 1349,15 @@ ENDXML
       doc.root.elements["item[@name='foo']"].to_s
   end
 
+  def test_ticket_138
+    doc = REXML::Document.new(
+      '<svg xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" ' +
+         'inkscape:version="0.44" version="1.0"/>'
+    )
+    assert_equal "<svg inkscape:version='0.44' version='1.0' xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape'/>", doc.root.to_s
+    assert_equal 3, doc.root.attributes.to_a.length
+  end
+
   def test_empty_doc
     assert(REXML::Document.new('').children.empty?)
   end