Skip to content

Instantly share code, notes, and snippets.

View dimerman's full-sized avatar
💻
coding

Dan Dimerman dimerman

💻
coding
  • 17:04 (UTC -07:00)
View GitHub Profile
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activerecord', require: 'active_record'
gem 'sqlite3'
gem 'lockbox', git: 'https://github.com/ankane/lockbox.git'
end
# USAGE: Hash.from_xml:(YOUR_XML_STRING)
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
return { result.root.name.to_sym => xml_node_to_hash(result.root)}