Skip to content

Instantly share code, notes, and snippets.

View chrisftw's full-sized avatar
🏠
Working from home

Chris Reister chrisftw

🏠
Working from home
  • Cavulus
  • Seattle, WA
View GitHub Profile
@chrisftw
chrisftw / Hash.from_xml using Nokogiri
Created April 17, 2012 23:46 — forked from dimus/Hash.from_xml using Nokogiri
Adding Hash.from_xml method using Nokogiri (properly handle attributtes and Cdata)
# 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 NokoHash < 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)}