# ActiveResource xml element ordering

**URL:** <https://www.ruby-forum.com/t/activeresource-xml-element-ordering/173061>\
**Category:** Rails\
**Created:** [August 1, 2009, 7:47am UTC](https://www.ruby-forum.com/t/activeresource-xml-element-ordering/173061 "2009-08-01T07:47:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![slavix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@slavix](https://www.ruby-forum.com/u/slavix)\
**Post date:** [August 1, 2009, 7:47am UTC](https://www.ruby-forum.com/t/activeresource-xml-element-ordering/173061/1 "2009-08-01T07:47:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![slavix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@slavix](https://www.ruby-forum.com/u/slavix)\
**Post date:** [August 1, 2009, 9:19pm UTC](https://www.ruby-forum.com/t/activeresource-xml-element-ordering/173061/2 "2009-08-01T21:19:02Z")

</div>

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  
  
  
  
$100  
\<maybe\_another\_attr\>\</maybe\_another\_attr\>

---

<div class="post-metadata">

**Author:** ![slavix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@slavix](https://www.ruby-forum.com/u/slavix)\
**Post date:** [August 2, 2009, 12:08am UTC](https://www.ruby-forum.com/t/activeresource-xml-element-ordering/173061/3 "2009-08-02T00:08:44Z")

</div>

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:///sales\_documents.xml  
body: \<?xml version="1.0" encoding="UTF-8"?\>  
  
  
  
3.0  
AD\_DASHERBOARD-200  
  
  
110  
10  
110  
Sales Lett  
10  
AG  
0000100007  
1100
