# XML builder templates/dashes in node names

**URL:** <https://www.ruby-forum.com/t/xml-builder-templates-dashes-in-node-names/71188>\
**Category:** Rails\
**Created:** [October 5, 2006, 10:58pm UTC](https://www.ruby-forum.com/t/xml-builder-templates-dashes-in-node-names/71188 "2006-10-05T22:58:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [October 5, 2006, 10:58pm UTC](https://www.ruby-forum.com/t/xml-builder-templates-dashes-in-node-names/71188/1 "2006-10-05T22:58:50Z")

</div>

Hi,

In an .rxml template, I need to have nodes named .  
However, if I use:

xml.cross-domain-policy

I get the following error:

undefined method `domain’

It works fine if I use xml.cross\_domain\_policy (undercores) to generate  
a tag \<cross\_domain\_policy\>. Unfortunately I need the dashes in the node  
names - how is it done?

Ingo

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [November 7, 2006, 10:55am UTC](https://www.ruby-forum.com/t/xml-builder-templates-dashes-in-node-names/71188/2 "2006-11-07T10:55:22Z")

</div>

For tags which have characters that are illegal in Ruby method names you  
can use the xml.tag! method in .rxml:

xml.tag! ‘cross-domain-policy’, ‘value’

or

xml.tag! ‘cross-domain-policy’ {  
xml…  
}

David S.

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [September 5, 2007, 6:01am UTC](https://www.ruby-forum.com/t/xml-builder-templates-dashes-in-node-names/71188/3 "2007-09-05T06:01:45Z")

</div>

David S. wrote:

> For tags which have characters that are illegal in Ruby method names you  
> can use the xml.tag! method in .rxml:
> 
> xml.tag! ‘cross-domain-policy’, ‘value’
> 
> or
> 
> xml.tag! ‘cross-domain-policy’ {  
> xml…  
> }
> 
> David S.

I cannot get this to work. I get an error in my Aptana IDE.

For example if I want to take:

```auto
xml.instruct!
xml.game_logs {
  xml.game{
    xml.name(@game.name)
    xml.id({:type => :integer}, @game.id)
  }
  @game_logs.each { |game_log|
    xml.game_log{
      xml.player {
        xml.name(game_log.player.login)
        xml.score(game_log.correct_answer_count)
      }
    }
  }
}
```

And make game\_log use dashes. What is the syntax? Thanks.

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [September 5, 2007, 6:14am UTC](https://www.ruby-forum.com/t/xml-builder-templates-dashes-in-node-names/71188/4 "2007-09-05T06:14:33Z")

</div>

Actually I got it working in that example.

```auto
xml.game_logs {
```

becomes

```auto
xml.tag!('game-logs') {
```

but what about here:

```auto
xml.is_correct({:type => :boolean}, answer.is_correct)
```

this does not work:

```auto
xml.tag!('is-correct', {:type => :boolean}, answer.is_correct)
```

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [September 5, 2007, 6:26am UTC](https://www.ruby-forum.com/t/xml-builder-templates-dashes-in-node-names/71188/5 "2007-09-05T06:26:15Z")

</div>

Nothing to see here - user error. That code works!

Thanks.
