Rails 1.2


#1

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:

Bob Jim Frank

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).


#2

On Jan 10, 2007, at 4:23 PM, Luke I. wrote:

talking it over with another programmer, I got to wondering, how would
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 = ’
Bob
Jim
Frank

=> “\n Bob\n Jim\n
Frank\n”

a = Hash.from_xml(xml)
=> {“listofnames”=>{“name”=>[“Bob”, “Jim”, “Frank”]}}

James.


James S.
blogging at http://jystewart.net


#3

Luke I. 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:

Bob Jim Frank

Hash.from_xml(“BobJim”)
=> {“listofnames”=>{“name”=>[“Bob”, “Jim”]}}

It doesn’t take long to just try something out. :slight_smile: I recommend
setting up a project using “edge Rails” so you can easily do this.

Dan M.


#4

Dan M. wrote:

Luke I. 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:

Bob Jim Frank

Hash.from_xml(“BobJim”)
=> {“listofnames”=>{“name”=>[“Bob”, “Jim”]}}

It doesn’t take long to just try something out. :slight_smile: I recommend
setting up a project using “edge Rails” so you can easily do this.

Dan M.

Thanks 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].