0

I have XML file, here part of it:

<advcampaign_categories>
    <category id="85">Sport</category>
    <category id="79">Gifts</category>
    <category id="87">Flowers</category>
    etc..
</advcampaign_categories>

and try to parse it like this:

url = 'my_xml_str' 
data = open(url).read
 Hash.from_xml(data).each do |k, v|
v['advcampaign_categories'] ...

then it returns me:

{"category"=>
  ["Sport",
   "Gifts",
   "Flowers"]
}

So my question is how to get category_id? if its possible or may be any other solutions?

Ideally, I want hash like this {sport:85,gifts:79}

Pinal
  • 10,391
  • 12
  • 45
  • 62
Katya
  • 128
  • 8

1 Answers1

0

It should be easy with a library that supports xpath (nokogiri for instance)

xpath exemple

Community
  • 1
  • 1
Thomas
  • 1,553
  • 6
  • 8