This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put this file eg. xml_parser.rb into your config/initializers directory, reboot your application | |
ActiveSupport::XmlMini.backend = "Nokogiri" | |
module ActiveSupport | |
module XmlMini_Nokogiri | |
def parse(data) | |
if !data.respond_to?(:read) | |
data = StringIO.new(data || '') | |
end | |
responds_to_getc = data.respond_to?(:getc) | |
if responds_to_getc | |
char = data.getc | |
data.ungetc(char) | |
end | |
if char.nil? && responds_to_getc | |
{} | |
else | |
doc = Nokogiri::XML(data) | |
raise doc.errors.first if doc.errors.length > 0 | |
doc.to_hash | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the above example, I've used the nokogiri gem for the backend parser, so you may need to add it to your Gemfile