Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #4049
| From | 7stud -- <bbxx789_05ss@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: newbie to using builder(for xml markup) |
| Date | 2011-05-06 12:33 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <41880a54835470e1996c9e43948b0dab@ruby-forum.com> (permalink) |
| References | <8c2481d112417ddf26d13fb9716372c6@ruby-forum.com> |
Brad Symons wrote in post #997015:
>
> I am just trying to understand how builder sorts the content of an xml
> node, because no matter how I arrange the options, they appears sorted
> differently in the irb.
1) The ordering of an xml element's attributes is irrelevant.
2) There are enough inconsistencies between irb and a real ruby program
that using irb to troubleshoot code is a waste of time.
>
> ids = ["1","2","3"]
> alphas = ["xxx","yyy","zzz"]
>
> xml = Builder::XmlMarkup.new( :target => $stdout, :indent => 2 )
> xml.instruct! :xml, :version => "1.1", :encoding => "US-ASCII"
>
> ids.each do |num|
> xml.programme(:alpha => alphas.fetch(ids.index(num)), :id => num)
> end
>
> Also, is there an easy way to map the values of the arrays together,
> than using the fetch method?
>
1)
ids.each_index do |i|
xml.programme(:alpha => alphas[i], :id => ids[i])
end
2)
ids = ["1","2","3"]
alphas = ["xxx","yyy","zzz"]
h = Hash[*alphas.zip(ids).flatten]
p h
--output:--
{"xxx"=>"1", "yyy"=>"2", "zzz"=>"3"}
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Find similar | Unroll thread
newbie to using builder(xml) Brad Symons <snomys@hotmail.com> - 2011-05-06 07:28 -0500
Re: newbie to using builder(for xml markup) Brad Symons <snomys@hotmail.com> - 2011-05-06 08:50 -0500
Re: newbie to using builder(for xml markup) Jeremy Bopp <jeremy@bopp.net> - 2011-05-06 10:06 -0500
Re: newbie to using builder(for xml markup) 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-06 12:33 -0500
csiph-web