Skip to content

Instantly share code, notes, and snippets.

@rcrigler
rcrigler / gist:3513521
Created August 29, 2012 14:38 — forked from thash/gist:2986414
Convert XML to Ruby Hash (using Nokogiri)
# USAGE: Hash.from_libxml(YOUR_XML_STRING)
# http://movesonrails.com/articles/2008/02/25/libxml-for-active-resource-2-0
require 'nokogiri'
# updated because original version is written in 2 years ago. - memerelics
class Hash
class << self
def from_libxml(xml)
begin
result = Nokogiri::XML(xml)
return { result.root.name.to_s.to_sym => xml_node_to_hash(result.root)}