Skip to content

Instantly share code, notes, and snippets.

@hisapy
Created May 8, 2015 16:32
Show Gist options
  • Save hisapy/352e3aec0ab01251049f to your computer and use it in GitHub Desktop.
Save hisapy/352e3aec0ab01251049f to your computer and use it in GitHub Desktop.
Create XML from Hash recursively using Nokogiri
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