Use builder to create an XML document from hash
#!/usr/bin/env ruby
require 'rubygems'
require 'builder'
favorites = {
'candy' => 'Neccos',
'novel' => 'Empire',
'holiday' => 'Easter'
}
xml = Builder::XmlMarkup.new( :target => $stdout, :indent => 2 )
xml.instruct! :xml, :version => "1.0", :encoding => "US-ASCII"
xml.favorites do
favorites.each do | name, choice |
xml.favorite( choice, :item => name )
end
end
Related examples in the same category