From: Lance Pollard Date: 2009-09-25T10:19:43+09:00 Subject: Re: Ordering XML Attributes with Hpricot? Thanks a lot axel, I'll give these a try Best, Lance Axel Etzold wrote: > Dear Lance, > > I accidentally hit the "send" button too early: > >> >> Since the attributes are kept in a hash there's no order to them, so >> they appear in seemingly random order, but it's the same random order >> consistently. >> >> Any ideas how to do that? >> > > a Hash can be sorted to give an Array with Hash#sort : > > http://ruby-doc.org/core/classes/Hash.html#M002865 > > >> And is there a way to say "after two attributes, make a new line". So I >> can print out xml that can be edited by humans like code. > > You can then iterate through the Array with Array#each_with_index, > eg. > > my_array.each_with_index{|x,i| if i%2==0 ; p x + "\n"; else p x; end} > > Best regards, > > Axel -- Posted via http://www.ruby-forum.com/.