Skip to content

Instantly share code, notes, and snippets.

@DerGuteMoritz
Created August 8, 2010 00:13
Show Gist options
  • Save DerGuteMoritz/513375 to your computer and use it in GitHub Desktop.
Save DerGuteMoritz/513375 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'nokogiri'
module SXML
def self.transform(sxml, doc = Nokogiri::XML::Document.new)
el = Nokogiri::XML::Element.new(sxml[0].to_s, doc)
sxml[1..-1].each do |e|
case e
when Array
el.add_child(transform(e, doc))
when String
el.content += e
when Fixnum
el.content += e.to_s
when Hash
e.each do |k,v|
el[k.to_s] = v
end
end
end
el
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment