Simple patch to allow to_xml for active record errors to return separate attribute and message tags

I have a simple patch for allowing active record errors to_xml to
return separate tags for attribute and message:

http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1625-allow-active-record-errors-to_xml-to-return-separate-tags-for-attribute-and-message

Review appreciated, thanks!

Scott Becker

-- for more info, keep reading --

I needed to return validation errors to an external program via web
service so that it could allow a user to fix them.

The standard errors.to_xml method only returns errors as full with
underscores converted to spaces, so there is no way for a program to
distinguish the attribute name from the error message.

This simple patch adds an :extended option to the to_xml method on the
Errors class, which will break out errors into separate "attribute"
and "message" tags for easier parsing by external programs. By default
this is set to false so existing code continues to work.

Example usage:

  company = Company.create(:address => '123 First St.')
  company.errors.to_xml(:extended => true)
  # => <?xml version="1.0" encoding="UTF-8"?>
  # <errors>
  # <error>
  # <attribute>name</attribute>
  # <message>is too short (minimum is 5 characters)</message>
  # </error>
  # <error>
  # <attribute>name</attribute>
  # <message>can't be blank</message>
  # </error>
  # <error>
  # <attribute>address</attribute>
  # <message>can't be blank</message>
  # </error>
  # </errors>

And the existing, standard output, which still works:

company = Company.create(:address => '123 First St.')
company.errors.to_xml
# => <?xml version="1.0" encoding="UTF-8"?>
# <errors>
# <error>Name is too short (minimum is 5 characters)</error>
# <error>Name can't be blank</error>
# <error>Address can't be blank</error>
# </errors>