# XML output generates dashes rather than underscore

**URL:** <https://www.ruby-forum.com/t/xml-output-generates-dashes-rather-than-underscore/181673>\
**Category:** Rails\
**Created:** [January 15, 2010, 8:36pm UTC](https://www.ruby-forum.com/t/xml-output-generates-dashes-rather-than-underscore/181673 "2010-01-15T20:36:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [January 15, 2010, 8:36pm UTC](https://www.ruby-forum.com/t/xml-output-generates-dashes-rather-than-underscore/181673/1 "2010-01-15T20:36:17Z")

</div>

Hey all,

I’m trying to change the xml output from a dash to underscore:

2010-01-15T17:00:23Z

to

\<updated\_at type=“datetime”\>2010-01-15T17:00:23Z\</updated\_at\>

Does anyone have any suggestions? Thanks.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [January 15, 2010, 8:58pm UTC](https://www.ruby-forum.com/t/xml-output-generates-dashes-rather-than-underscore/181673/2 "2010-01-15T20:58:40Z")

</div>

John M. wrote:

> Hey all,
> 
> I’m trying to change the xml output from a dash to underscore:
> 
> 2010-01-15T17:00:23Z
> 
> to
> 
> \<updated\_at type=“datetime”\>2010-01-15T17:00:23Z\</updated\_at\>
> 
> Does anyone have any suggestions? Thanks.

## An excerpt from the Rails docs on to\_xml: [http://www.railsbrain.com/api/rails-2.3.2/doc/index.html?a=M001926&name=to\_xml](http://www.railsbrain.com/api/rails-2.3.2/doc/index.html?a=M001926&name=to_xml)

## This behavior can be controlled with :only, :except, :skip\_instruct, :skip\_types, :dasherize and :camelize . The :only and :except options are the same as for the attributes method. The default is to dasherize all column names, but you can disable this setting :dasherize to false. Setting :camelize to true will camelize all column names - this also overrides :dasherize. To not have the column type included in the XML output set :skip\_types to true.

@model.to\_xml :dasherize =\> false

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [January 15, 2010, 8:59pm UTC](https://www.ruby-forum.com/t/xml-output-generates-dashes-rather-than-underscore/181673/3 "2010-01-15T20:59:53Z")

</div>

Hi John,

On Fri, 2010-01-15 at 20:36 +0100, John M. wrote:

> I’m trying to change the xml output from a dash to underscore:

What are you using to generate the xml ? There are several options.

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [January 15, 2010, 9:02pm UTC](https://www.ruby-forum.com/t/xml-output-generates-dashes-rather-than-underscore/181673/4 "2010-01-15T21:02:15Z")

</div>

On Fri, 2010-01-15 at 20:36 +0100, John M. wrote:

> I’m trying to change the xml output from a dash to underscore:

Just in case, if you’re using the to\_xml method, add :dasherize =\> false  
to the options.

HTH,  
Bill
