Skip to content

happymapper

152 7 24 MIT
0.10.0 (5 Jan 2024) Mar 19 2010 25.6 thousand (month)

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)

Alternatives / Similar


ox
897 2.14.18 (3 months ago) Jul 01 2011 compare
222 4.2.0 (2 years ago) Aug 05 2009 compare

Other Languages

Was this page helpful?