Define id in xml

require 'builder'

builder = Builder::XmlMarkup.new(:indent => 2)

xml = builder.users do |users|
  (1..2).each do |user_id|
    users.user(:id => user_id) do |u|
      u.email("foo")
    end
  end
end

puts xml

#=>

<users>
  <user id="1">
    <email>foo</email>
  </user>
  <user id="2">
    <email>foo</email>
  </user>
</users>

Thanks for the help