Using a namespace prefix with the rexle-builder gem

require 'rexle'
require 'rexle-builder'

xml = RexleBuilder.new
a = xml.root do
  xml['abc'].fun do
    xml.tree({country: 'Canada'}, 'mahogany')
  end
  xml['fgh'].green 'leaves'
end

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


output:

<?xml version='1.0' encoding='UTF-8'?>
<root>
  <abc:fun>
    <tree country='Canada'>mahogany</tree>
  </abc:fun>
  <fgh:green>leaves</fgh:green>
</root>

Resources

Tags:
Source:
1629hrs.txt
Published:
17-09-2014 16:29