Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
parse an xml snippet to a hash
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
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:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
doug livesey  
View profile   Translate to Translated (View Original)
 More options 2 July, 11:23
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.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Will Jessop  
View profile   Translate to Translated (View Original)
 More options 2 July, 11:29
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/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
doug livesey  
View profile   Translate to Translated (View Original)
 More options 2 July, 11:33
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.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Will Jessop  
View profile   Translate to Translated (View Original)
 More options 2 July, 11:37
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/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Tickle  
View profile   Translate to Translated (View Original)
 More options 2 July, 11:46
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
doug livesey  
View profile   Translate to Translated (View Original)
 More options 2 July, 11:48
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!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Chambers  
View profile   Translate to Translated (View Original)
 More options 2 July, 12:28
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
doug livesey  
View profile   Translate to Translated (View Original)
 More options 2 July, 13:04
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.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google