It appears that the same problem exists with Builder.  From
http://builder.rubyforge.org/:

"The order that attributes are inserted in markup tags is undefined."

Interestingly, though, the _special method exists, which is used by Builder
itself to enforce the ordering of XML attributes in the  XML processing
instruction typically found on the first line of an XML file.  In this
case, they ensure that the order is version, encoding, standalone:

 def instruct!(directive_tag=:xml, attrs={})
      _ensure_no_block ::Kernel::block_given?
      if directive_tag == :xml
        a = { :version=>"1.0", :encoding=>"UTF-8" }
        attrs = a.merge attrs
    @encoding = attrs[:encoding].downcase
      end
      _special(
        "<?#{directive_tag}",
        "?>",
        nil,
        attrs,
        [:version, :encoding, :standalone])
    end

-jon