Ok, I have no clue where to post this, so if I''m in the wrong forum,
just tell me, and I''ll take a hike.
That being said:
I was looking at the rubyonrails.org weblog site, and was reading of the
updates to Active Support.
One that caught my attention was the Hash.from_xml function... as I was
talking it over with another programmer, I got to wondering, how would
it deal with something like:
<listofnames>
<name>Bob</name>
<name>Jim</name>
<name>Frank</name>
</listofnames>
The structure they showed seemed to imply that a hash would be created
using the tag name as the key, and the information contained in the tag
as the value. So if there are three tags named ''name'', does
you just
get {:listofnames => {:name => "Frank"}}?
I also tried to post this in Rails Engines, but apparently you have to
be a member of that list, which I don''t want to be unless absolutely
necessary (not from any reason other than if I''m only going to post to
it once, I don''t see the need to become a member).
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Jan 10, 2007, at 4:23 PM, Luke Ivers wrote:> Ok, I have no clue where to post this, so if I''m in the wrong forum, > just tell me, and I''ll take a hike. > > That being said: > I was looking at the rubyonrails.org weblog site, and was reading > of the > updates to Active Support. > > One that caught my attention was the Hash.from_xml function... as I > was > talking it over with another programmer, I got to wondering, how would > it deal with something like: > > <listofnames> > <name>Bob</name> > <name>Jim</name> > <name>Frank</name> > </listofnames> > > The structure they showed seemed to imply that a hash would be created > using the tag name as the key, and the information contained in the > tag > as the value. So if there are three tags named ''name'', does you just > get {:listofnames => {:name => "Frank"}}?If there are multiple elements with the same name then rails will return those as an array: $ script/console >> xml = ''<listofnames> <name>Bob</name> <name>Jim</name> <name>Frank</name> </listofnames>'' => "<listofnames>\n <name>Bob</name>\n <name>Jim</name>\n <name>Frank</name>\n</listofnames>" >> a = Hash.from_xml(xml) => {"listofnames"=>{"name"=>["Bob", "Jim", "Frank"]}} James. -- James Stewart blogging at http://jystewart.net --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Luke Ivers wrote:> One that caught my attention was the Hash.from_xml function... as I was > talking it over with another programmer, I got to wondering, how would > it deal with something like: > > <listofnames> > <name>Bob</name> > <name>Jim</name> > <name>Frank</name> > </listofnames>>> Hash.from_xml("<listofnames><name>Bob</name><name>Jim</name></listofnames>")=> {"listofnames"=>{"name"=>["Bob", "Jim"]}} It doesn''t take long to just try something out. :-) I recommend setting up a project using "edge Rails" so you can easily do this. Dan Manges --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dan Manges wrote:> Luke Ivers wrote: >> One that caught my attention was the Hash.from_xml function... as I was >> talking it over with another programmer, I got to wondering, how would >> it deal with something like: >> >> <listofnames> >> <name>Bob</name> >> <name>Jim</name> >> <name>Frank</name> >> </listofnames> > >>> Hash.from_xml("<listofnames><name>Bob</name><name>Jim</name></listofnames>") > => {"listofnames"=>{"name"=>["Bob", "Jim"]}} > > It doesn''t take long to just try something out. :-) I recommend > setting up a project using "edge Rails" so you can easily do this. > > Dan MangesThanks to you, and also to James. Still new enough to the whole thing that doing that didn''t occur to me; I''ll do so in the future, though [I try to only make mistakes that make me appear a completely clueless newbie once]. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---