ActiveResource xml element ordering

Hello,
I am using ActiveResource to integrate with a 3rd party service.
when calling MyModel.save a POST with xml is sent.
I need to make sure that xml is created with defined order of
elements. How can I do that?
Some have suggested using rxml or builder, but I am not sure how. Has
anyone done this before?

thank you

I'm not sure what you mean by order, but if you are working with a
list of items you can order the array and the to_xml will reflect
that. Otherwise if by order you mean having different xml blocks in a
post request then use a hash. The order in which the items are
contained within the xml won't matter as long as they are all there
and in the proper structure. For example, say we are using a person a
payment and a product, and the payment is in the person block.

h = Hash.new
h['person'] = Person.first.attributes
h['person']['payment'] = "$100.00"
h['product'] = Product.first
h.to_xml(:root => 'notification')

would result
<notification>
  <person>
     <attr></attr>
      <payment>$100</payment>
      <maybe_another_attr></maybe_another_attr>
  </person>
  <product>
     <attr></attr>
     <attr2></attr2>
  </product>
</notification>

SalesDocument < ActiveResource

I need to make sure that when I call

SalesDocument.save

the order of elements in the xml is predetermined and consistent,
which currently not the case.

POST http://<myurl>/sales_documents.xml
body: <?xml version="1.0" encoding="UTF-8"?>
<sales-document>
  <items type="array">
    <item>
      <quantity type="float">3.0</quantity>
      <product>AD_DASHERBOARD-200</product>
    </item>
  </items>
  <sales-group>110</sales-group>
  <division>10</division>
  <sales-office>110</sales-office>
  <ref-inquiry>Sales Lett</ref-inquiry>
  <distr-channel>10</distr-channel>
  <document-type>AG</document-type>
  <customer>0000100007</customer>
  <sales-org>1100</sales-org>
</sales-document>