Created
August 8, 2010 00:13
-
-
Save DerGuteMoritz/513375 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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