libxml-ruby

Convert a Nokogiri document to a Ruby Hash

[亡魂溺海] 提交于 2019-11-26 06:28:07
问题 Is there an easy way to convert a Nokogiri XML document to a Hash? Something like Rails\' Hash.from_xml . 回答1: I use this code with libxml-ruby (1.1.3). I have not used nokogiri myself, but I understand that it uses libxml-ruby anyway. I would also encourage you to look at ROXML (http://github.com/Empact/roxml/tree) which maps xml elements to ruby objects; it is built atop libxml. # USAGE: Hash.from_libxml(YOUR_XML_STRING) require 'xml/libxml' # adapted from # http://movesonrails.com/articles