Skip to content

Instantly share code, notes, and snippets.

@bcalloway
Created November 3, 2009 16:56
Show Gist options
  • Save bcalloway/225218 to your computer and use it in GitHub Desktop.
Save bcalloway/225218 to your computer and use it in GitHub Desktop.
Parse XML file with Nokogiri
xml = File.read("db/getLocationsForUrl.xml")
@doc = Nokogiri::XML.parse(xml)
locations = []
locations.push("<option value=\"\">-- Select a Location --</option>")
@doc.xpath('/env:Envelope/env:Body/Array/item/return/item').each do |node|
id = node.xpath('id')
name = node.xpath('name')
locations.push("<option value=\"#{id.text}\">#{name.text}</option>")
end
return locations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment