Hi Hunter,
quick and dirty:
Hash[*xml.scan(%r{>([^>]*)</f>}).flatten]
returns
{"12"=>"AAF",
"7"=>"AAE",
"13"=>"AAG",
"8"=>"AAA",
"9"=>"ISA",
"1"=>"AAA",
"2"=>"AAB",
"4"=>"AAC",
"5"=>"AAD"}
cheers
Simon
···
-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Hunter Walker
Sent: Monday, May 08, 2006 8:31 AM
To: ruby-talk ML
Subject: new to Ruby and XMLHi all,
I have an API call to another database app that returns the XML below:
<records> <record> <f id='3'>9</f> <f
id='8'>ISA</f> </record> <record> <f
id='3'>8</f>
<f id='8'>AAA</f> </record> <record> <f
id='3'>1</f> <f id='8'>AAA</f> </record>
<record>
<f id='3'>2</f> <f id='8'>AAB</f> </record>
<record> <f id='3'>4</f> <f id='8'>AAC</f>
</record> <record> <f id='3'>5</f> <f
id='8'>AAD</f> </record> <record> <f
id='3'>7</f>
<f id='8'>AAE</f> </record> <record> <f
id='3'>12</f> <f id='8'>AAF</f> </record>
<record> <f id='3'>13</f> <f id='8'>AAG</f>
</record> </records>I'd like to loop through each of these records and create a
hash. The
first value of each record being the key and the second being
the value
in the hash.Any ideas? Thank you for helping a noob!
-Hunter
--
Posted via http://www.ruby-forum.com/\.