From: Dustin Barker Date: 2008-07-25T01:49:14+09:00 Subject: Re: Output an array as XML Hi Chris, > > Im currently trying to do it with builder and have the following: urls = ["http://www.google.com", "http://yahoo.com"] > @sitemap = Builder::XmlMarkup.new() > @sitemap.instruct! > @sitemap.declare! :DOCTYPE, :html, :PUBLIC, "-//W3C//DTD XHTML 1.0 > Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" @sitemap.urlset can take a block as a parameter: > > @sitemap.urlset("xmlns" => > "http://www.sitemaps.org/schemas/sitemap/0.9") it becomes: @sitemap.urlset("xmlns" => "http://www.sitemaps.org/schemas/sitemap/ 0.9") do |urlset| urls.each do |loc| urlset.url { |url| url.loc(loc) } end end The block argument 'urlset' is effectively the urlset tag and behaves the same way as @sitemap. The block that is passed to @sitemap.urlset can iterate the array of URLs and build the child nodes (also using blocks to build their children and so on). -Dustin