Building XML from a Hash object

require 'rexle'
require 'rexle-builder'

h = {fun: '123', colour: 'red', weather: {edinburgh: 'sunny'}}
a = RexleBuilder.new(h).to_a

# ... or

h = {fun: '123', colour: 'red', weather: ['edinburgh', {}, 'sunny']}
a = RexleBuilder.new(h).to_a

puts Rexle.new(a).xml pretty: true


Output:

<?xml version='1.0' encoding='UTF-8'?>
<root>
  <fun>123</fun>
  <colour>red</colour>
  <weather>
    <edinburgh>sunny</edinburgh>
  </weather>
</root>