happymapper
Happymapper allows you to parse XML data and convert it quickly and easily into ruby data structures.
Happymapper maps XML structures to ruby data structures which then can be parsed for data using any other Ruby data tools. This also means, happymaker can convert XML to JSON as ruby data structures are easily exportable to JSON
Example Use
require 'happymapper'
xml = '<address>
<street>Milchstrasse</street>
<housenumber>23</housenumber>
<postcode>26131</postcode>
<city>Oldenburg</city>
<country code="de">Germany</country>
</address>'
# we can parse it as is:
address = HappyMapper.parse(ADDRESS_XML_DATA)
address.street # => Milchstrasse
address.housenumber # => 23
address.postcode # => 26131
address.city # => Oldenburg
address.country.code # => de
address.country.content # => Germany
# or define a structure
class Address
include HappyMapper
tag 'address'
element :street, String, tag: 'street'
element :postcode, String, tag: 'postcode'
element :housenumber, Integer, tag: 'housenumber'
element :city, String, tag: 'city'
element :country, String, tag: 'country'
end
Address.parse(xml)