Question: I'm building an API for my app and would like to return errors in the XML response that are generated by validation errors.

So say you're registering on the site, right now the validation errors returned might be:

```
Login has already been taken
Password is too short (minimum is 6 characters)
Email has already been taken

```

But I'd like to reformat that as:

```
<errors>
    <error>Login has already been taken</error>
    <error>Password is too short (minimum is 6 characters)</error>
    <error>Email has already been taken</error>
</errors>

```

So, how would I access the validation error array to do that?

Answer: 
Rails gives you this functionality by default, i.e.

```
  user.errors.to_xml

```

Will give you

```
=>  <?xml version="1.0" encoding="UTF-8"?>
    <errors>  
     <error>Name can't be blank</error>
     <error>Wiki url can't be blank</error>
     <error>User can't be blank</error>
    </errors>

```

Rails 7

```
user.errors.to_hash.to_xml

```
The model object will have an [errors](http://api.rubyonrails.org/classes/ActiveRecord/Errors.html) object that you can iterate, some examples in the [validations](http://api.rubyonrails.org/classes/ActiveRecord/Validations.html) doc.