Skip to content

Instantly share code, notes, and snippets.

@mperham
Forked from tenderlove/builder.rb
Created September 4, 2009 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mperham/181138 to your computer and use it in GitHub Desktop.
Save mperham/181138 to your computer and use it in GitHub Desktop.
require 'nokogiri'
xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
xml.feed(
:xmlns => 'http://www.w3.org/2005/Atom',
'xmlns:osa' => 'http://www.onespot.com/Atom/Extensions/1.0'
) do
xml.title 'feed title', :type => "html"
xml.entry do |ctx|
###
# default namespace
xml.title 'entry title', :type => "html"
###
# "osa" namespace
xml[:osa].score(0.50)
###
# All of these tags belong to the "onespot" namespace
ctx.with_namespace(:osa) do
xml.foo(0.50)
xml.bar(0.50)
###
# Including these tags
xml.baz do
xml.yay
end
end
end
end
end.to_xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment