Created
May 8, 2015 16:32
-
-
Save hisapy/352e3aec0ab01251049f to your computer and use it in GitHub Desktop.
Create XML from Hash recursively using Nokogiri
This file contains 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
hash_tree = {} # hash where all the members are also hashes, even the "leaf nodes" | |
def xml_node(node, children, xml) | |
xml.send(node){ | |
children.each do | n, c | | |
xml_node(n, c, xml) | |
end | |
} | |
end | |
builder = Nokogiri::XML::Builder.new do | xml | | |
xml.root { | |
hash_tree.each do | k, v | | |
xml_node(k, v, xml) | |
end | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment