Skip to content

Instantly share code, notes, and snippets.

@gunn
Created August 19, 2010 08:48
Show Gist options
  • Save gunn/537425 to your computer and use it in GitHub Desktop.
Save gunn/537425 to your computer and use it in GitHub Desktop.
Custom xml demo for IRC user
def custom_xml hash
Builder::XmlMarkup.new(:indent => 2).tags do |tag|
hash.each do |key, val|
tag.tag! key do |v|
v.value val
end
end
end
end
custom_xml({:course => 'Java', :year => 'VT2010', :assignment => '1', :student => '2'})
<tags>
<assignment>
<value>1</value>
</assignment>
<student>
<value>2</value>
</student>
<year>
<value>VT2010</value>
</year>
<course>
<value>Java</value>
</course>
</tags>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment