Rails 3.0 Parsing XML and Inserting into Database

后端 未结 3 2067
星月不相逢
星月不相逢 2021-02-11 08:48

I\'m new to Rails, and am trying to hook up my application to a third-party API (it does\'t have a gem or plugin for Rails).

Ideally, what I want to be able to do is par

3条回答
  •  半阙折子戏
    2021-02-11 09:12

    When using nokogiri you can specify css or xpath selectors, like:

    doc = Nokogiri::XML(xml_string)
    events = doc.search('//event')
    events.each do |event|
      puts event.at('short_description')
    end
    

    Also, check out nokogiri intro tutorials.

提交回复
热议问题