简体   繁体   中英

How to I GET an XML page and parse it into a Ruby hash in Rails?

Assuming my xml response is at example.com/query , how do I parse it into a Ruby hash without using external dependencies like Nokogiri?

Also, and not really part of the question, why would anyone use XML?

This is trivial:

require 'open-uri'

url = 'example.com/query'
h = Hash.from_xml(open url)

This example needs Hash#from_xml from Rail's active_support/core_ext/hash and will not work with Vanilla Ruby.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM