parse an xml snippet to a hash
The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
From:
doug livesey <biot... @gmail.com>
Date: Thu, 2 Jul 2009 11:23:21 +0100
Local: Thurs 2 July 2009 11:23
Subject: parse an xml snippet to a hash
Hi -- I have a custom ActiveResource action that returns the following xml:
"<result>\n <successes>\n <1>a082000000HqJzUAAV</1>\n <2>a082000000HqJzsAAF</2>\n <3>a082000000HqJzVAAV</3>\n </successes>\n <failures>\n </failures>\n</result>\n"
Is there a quick & easy way to turn this into the following hash?
{ "result" { "successes" => { "1" => "a082000000HqJzUAAV", "2" => "a082000000HqJzsAAF", "3" => "a082000000HqJzVAAV" }, "failures" => {} }
Or should I go off & learn hpricot like I've been meaning to for ~3 years? Cheers, Doug.
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Will Jessop <w... @willj.net>
Date: Thu, 2 Jul 2009 11:29:15 +0100
Local: Thurs 2 July 2009 11:29
Subject: Re: [NWRUG] parse an xml snippet to a hash
On 2 Jul 2009, at 11:23, doug livesey wrote:
> Hi -- I have a custom ActiveResource action that returns the
> following xml:
> "<result>\n <successes>\n <1>a082000000HqJzUAAV</1>\n > <2>a082000000HqJzsAAF</2>\n <3>a082000000HqJzVAAV</3>\n </ > successes>\n <failures>\n </failures>\n</result>\n"
> Is there a quick & easy way to turn this into the following hash?
> { "result" { "successes" => { "1" => "a082000000HqJzUAAV", "2" => > "a082000000HqJzsAAF", "3" => "a082000000HqJzVAAV" }, "failures" => > {} }
This might help:
http://xml-mapping.rubyforge.org/
Not used it myself though.
Will.
-- Will Jessop Super Shiny Robot Limited - Professional web design and development
t: 07939 547 962 w: http://supershinyrobot.com/
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
doug livesey <biot... @gmail.com>
Date: Thu, 2 Jul 2009 11:33:46 +0100
Local: Thurs 2 July 2009 11:33
Subject: Re: [NWRUG] Re: parse an xml snippet to a hash
Interesting, cheers! Probably a little heavy-duty for me right now, but bookmarked for future reference. Cheers, Doug.
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Will Jessop <w... @willj.net>
Date: Thu, 2 Jul 2009 11:37:23 +0100
Local: Thurs 2 July 2009 11:37
Subject: Re: [NWRUG] Re: parse an xml snippet to a hash
On 2 Jul 2009, at 11:33, doug livesey wrote:
> Interesting, cheers! > Probably a little heavy-duty for me right now, but bookmarked for > future reference.
That's what I thought when I looked at the page. Personally I usually
just mangle XML using libXML, I actually don't mind the syntax myself.
Will.
-- Will Jessop Super Shiny Robot Limited - Professional web design and development
t: 07939 547 962 w: http://supershinyrobot.com/
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Steve Tickle <st... @sixteenk.net>
Date: Thu, 2 Jul 2009 11:46:49 +0100
Local: Thurs 2 July 2009 11:46
Subject: Re: [NWRUG] parse an xml snippet to a hash
learn Hpricot regardless, it's jQuery selectors for rubyists!
Although your <1>, <2>, <3> style XML grammar feels a bit odd and doesn't
really lend itself to xpath or css selection ...
Cheers,
Steve
On Thu, Jul 2, 2009 at 11:23 AM, doug livesey <biot
... @gmail.com> wrote:
> Hi -- I have a custom ActiveResource action that returns the following xml:
> "<result>\n <successes>\n <1>a082000000HqJzUAAV</1>\n
> <2>a082000000HqJzsAAF</2>\n <3>a082000000HqJzVAAV</3>\n </successes>\n
> <failures>\n </failures>\n</result>\n"
> Is there a quick & easy way to turn this into the following hash?
> { "result" { "successes" => { "1" => "a082000000HqJzUAAV", "2" =>
> "a082000000HqJzsAAF", "3" => "a082000000HqJzVAAV" }, "failures" => {} }
> Or should I go off & learn hpricot like I've been meaning to for ~3 years?
> Cheers,
> Doug.
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
doug livesey <biot... @gmail.com>
Date: Thu, 2 Jul 2009 11:48:23 +0100
Local: Thurs 2 July 2009 11:48
Subject: Re: [NWRUG] Re: parse an xml snippet to a hash
> Although your <1>, <2>, <3> style XML grammar feels a bit odd and doesn't
really lend itself to xpath or css selection ...
Just realising that, now! Bit of a rethink on the return document, I think!
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Paul Chambers <paul.chamb... @gmail.com>
Date: Thu, 2 Jul 2009 12:28:09 +0100
Local: Thurs 2 July 2009 12:28
Subject: Re: [NWRUG] parse an xml snippet to a hash
On Thu, Jul 2, 2009 at 11:23 AM, doug livesey<biot
... @gmail.com> wrote:
> Is there a quick & easy way to turn this into the following hash?
Activesupport adds Hash.from_xml which should do what you want.
Or you could try the cobravsmongoose gem: http://cobravsmongoose.rubyforge.org/
Paul
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
doug livesey <biot... @gmail.com>
Date: Thu, 2 Jul 2009 13:04:58 +0100
Local: Thurs 2 July 2009 13:04
Subject: Re: [NWRUG] Re: parse an xml snippet to a hash
> Activesupport adds Hash.from_xml which should do what you want.
> Or you could try the cobravsmongoose gem:
http://cobravsmongoose.rubyforge.org/ cobravsmongoose looks very interesting for the future, but for now the Hash.from_xml is damn' near perfect! Just returns a blank hash as the string "/n ", which I can deal with easily enough. Thank very much! Doug.
You must
Sign in before you can post messages.
You do not have the permission required to post.