I am parsing an xml result using Hpricot, amazing ..
I have a serie of tags to be transformed as parameters, so I am
building Hash by looping on these tags , the resulting data is oK? but
I ma not sure that I wrote a dry code
.......
if doc.search(''response > error'').innerHTML.empty?
accountTypes = []
(doc/:accounttype).each do |accountType|
data = {}
....
data[:locale] (accountType/:localized/:locale/:code).innerHTML
data[:title] (accountType/:localized/:locale/:title).innerHTML
....
... # here is the loop over the <tags> elements
tags = {}
(accountType/:tag).each do |tag|
key = (tag/:name).innerHTML.to_s
value = (tag/:value).innerHTML.to_s
tags.store(key, value)
end
.....# end of the loop , storing the data
data[:tags] = tags
accountTypes << data
end
Is this loop OK ?
tags = {}
(accountType/:tag).each do |tag|
key = (tag/:name).innerHTML.to_s
value = (tag/:value).innerHTML.to_s
tags.store(key, value)
end
thanks for you fedback
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.