Use builder to create an XML document from hash : XML Builder « XML « Ruby






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

1.Create an XML document from a here document
2.Builder::XmlMarkup.new( :target => address, :indent => 1 )
3.XmlMarkup