ActiveSupport adds a to_xml
method to Hash, so you can get pretty close to what you are looking for with this:
sudo gem install activesupport
require "active_support/core_ext"
my_hash = { :first_name => 'Joe', :last_name => 'Blow', :email => '[email protected]'}
my_hash.to_xml(:root => 'customer')
And end up with:
<?xml version="1.0" encoding="UTF-8"?>
<customer>
<last-name>Blow</last-name>
<first-name>Joe</first-name>
<email>[email protected]</email>
</customer>
Note that the underscores are converted to dashes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…