Skip to content

Instantly share code, notes, and snippets.

@wrburgess
Created March 2, 2012 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wrburgess/1961127 to your computer and use it in GitHub Desktop.
Save wrburgess/1961127 to your computer and use it in GitHub Desktop.
Nokogiri parse XML example
doc = Nokogiri::XML(res.body)
@doc = doc.xpath('//mdn').each do |record|
@carriercode = record.at('@carrier').text
end
@carriercode
unless params[:type].nil?
doc = Nokogiri::XML(File.read("app/assets/files/schedule_nba.xml"))
@doc = doc.xpath('//listing').each do |record|
Game.create(
:awayteamid => record.at('@awayteamid').text,
:awayteamname => record.at('awayteam').text,
:hometeamid => record.at('@hometeamid').text,
:hometeamname => record.at('hometeam').text,
:gamedate => DateTime.strptime(record.at('Game_Date').text, "%m/%d/%Y")
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment