Phlip
3/11/2009 4:44:00 AM
Naresh Ramaswamy wrote:
> Thank you for the solution, it almost worked to me, but when I apply it
> on my xml document I am getting the output from reverse order, why so?
> <REMOVE_1 header='req_line' mname='InVIte'
> uri='tel:naresh@span.com'/>
> I applied the code for the element "REMOVE_1" and observe the following
> as the output.
>
> -----output------
> tel:naresh@span.com
> InVIte
> req_line
> -----------------
XML has a concept of document order, but not of attribute order within one tag.
XML readers are (apparently) not required to remember there order.
Next, the attributes come in a Hash, and this has a BUG (!) which will be FIXED
(!) in the next Ruby versions. It can't preserve the order you inserted its keys.
Until then, your own code must put the keys into the order you need. Try
element.attributes.to_a.sort
to put them into asciibetic order, for example.