Hello,

Just to get it out of the way, yes, I've searched the lists and yes, I am
well aware that attribute ordering in XML elements shouldn't matter.
 Additionally, yes, I am well aware of the Nokogiri mailing list, however
Google won't let me join the group and I can't post without joining.  So,
here I am.

However, my use case is slightly different.  The code I am using that
ultimately writes XML files will switch the ordering of XML attributes that
it generates depending on what version of Ruby is used to run the code,
what state the code is in, etc.  The end result is that if I had an XML
file A with the following content at time 0:

<Foo>
   <Bar blaf="1" what="stuff"/>
</Foo>

At time > 0, where this file is regenerated either on a different machine,
with ever so slightly modified code (but the order as defined with the
Builder is the same), the order changes.  When these resulting files are in
some sort of revision control, it looks like they are changing on a regular
basis but in reality its just the attribute ordering.

Does anyone have any tried and true solutions that enforce ordering of XML
attributes with Nokogiri::XML::Builder?

I have had some level of success with the following practice:

stub_xml = "<Foo>"
stub_xml += "<Bar blaf=\"1\" what=\"stuff\"/>"
stub_xml += </Foo>"

builder = Nokogiri::XML::Builder.with(Nokogiri::XML(stub_xml).at("Foo") do
|xml|
  # usual builder stuff here
end

This only works for really simple XML, and for XML that is deeply nested,
the "stub" XML becomes so large that I often just end up writing the XML
generation code by hand.

Any suggestions would be appreciated!  Please note that I am not tied to
Nokogiri::XML::Builder for XML building.  I have heard that I can
accomplish something similar with Rexml.

Thanks,

-jon