Skip to content

Instantly share code, notes, and snippets.

@dineshsprabu
Created June 27, 2016 05:54
Show Gist options
  • Save dineshsprabu/a80be0d1e80e17a57bd7b7a72182fb0f to your computer and use it in GitHub Desktop.
Save dineshsprabu/a80be0d1e80e17a57bd7b7a72182fb0f to your computer and use it in GitHub Desktop.
[RUBY] How to convert XML to HASH?
require 'active_support/core_ext/hash/conversions'
def xml_to_hash filename
doc = Nokogiri::XML.parse(File.open(filename))
Hash.from_xml(doc.to_s)
end
p xml_to_hash 'file/to/path/filename.xml'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment