REXML Attribute and Quotation Control

I am using REXML to open an XML file, modify some elements, and write a
new XML with the modified elements. That part is working wonderfully;
however, REXML is also changing all attribute quotes from double to
single (I want them to remain double) and it is reordering all my
attributes according to no discernible pattern (I want the attribute
order to remain the same). Has anyone encountered this and know of a
solution? I know I could solve the quotation issue with some regex
find/replace, but maybe there is a more elegant solution; and I don’t
have any idea how to handle the attribute order.

I’m also warning to know the answer.

See
http://stackoverflow.com/questions/3927507/ruby-convert-single-quotes-to-double-quotes-in-xml

Nic wrote in post #973817:

See

http://stackoverflow.com/questions/3927507/ruby-convert-single-quotes-to-double-quotes-in-xml

It works, but double quote don’t apply to “<?xml version=‘1.0’
encoding=‘UTF-8’?>”

That is hardcoded in the XMLDecl class. From source:

private
def content(enc)
rv = “version=’#@version’”
rv << " encoding=’#{enc}’" if @writeencoding || enc !~ /utf-8/i
rv << " standalone=’#@standalone’" if @standalone
rv
end

You could use the similar code that is suggested in the second answer of
the SO post to replace the content() method.