Just to get it out of the way, yes, I’ve searched the lists and yes, I
well aware that attribute ordering in XML elements shouldn’t matter.
Additionally, yes, I am well aware of the Nokogiri mailing list,
Google won’t let me join the group and I can’t post without joining.
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
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:
At time > 0, where this file is regenerated either on a different
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
some sort of revision control, it looks like they are changing on a
basis but in reality its just the attribute ordering.
Does anyone have any tried and true solutions that enforce ordering of
attributes with Nokogiri::XML::Builder?
I have had some level of success with the following practice:
stub_xml = “”
stub_xml += “<Bar blaf=“1” what=“stuff”/>”
stub_xml += "
builder = Nokogiri::XML::Builder.with(Nokogiri::XML(stub_xml).at(“Foo”)
usual builder stuff here
This only works for really simple XML, and for XML that is deeply
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.