Skip to content

Instantly share code, notes, and snippets.

@smtm
Created February 14, 2012 12:39
Show Gist options
  • Save smtm/1826578 to your computer and use it in GitHub Desktop.
Save smtm/1826578 to your computer and use it in GitHub Desktop.
nokogiri rename root
# I'm sort of new to this XML stuff and maybe I haven't grokked the basics , but here's what I am trying to do
# I need about 10 different request to a server and they share common code. I want to keep things DRY
# and use a sort of template system where the "header stuff stays the same and I use partials to inject into
# the XML tree
require 'rubygems'
require 'nokogiri'
module Nokfun
def self.nokbuild(method name)
builder = Nokogiri::XML::Builder.new do |xml|
#method_name should be the root element
xml.yahoo {
xml.products {
xml.widget {
xml.id_ "10"
xml.name "Awesome widget"
}
}
}
end
#trying to inject the code
b2 = Nokogiri::XML::Builder.new do |xml|
xml.wohoo {
xml << builder
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment