# Issue generating XML with hyphenated element names

**URL:** <https://www.ruby-forum.com/t/issue-generating-xml-with-hyphenated-element-names/90123>\
**Category:** Rails\
**Created:** [March 26, 2007, 7:36am UTC](https://www.ruby-forum.com/t/issue-generating-xml-with-hyphenated-element-names/90123 "2007-03-26T07:36:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjudge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ebca7d/32.png) [@jjudge](https://www.ruby-forum.com/u/jjudge)\
**Post date:** [March 26, 2007, 7:36am UTC](https://www.ruby-forum.com/t/issue-generating-xml-with-hyphenated-element-names/90123/1 "2007-03-26T07:36:57Z")

</div>

Hello…

I’m trying to generate and XML file using .rxml and I’m having a  
problem with element names that contain a hyphen. Here is a chunk of  
the .rxml file:

xml.instruct! :xml, :version=\>“1.0”  
xml.properties do  
@properties.each do |p|  
xml.property do  
xml.location do  
xml.street-address(p.street\_address)  
xml.city-name(p.city)  
…  
end  
end  
end  
end

As soon as the code hits the street-address line, a NoMethodError is  
thrown:

undefined method `address’ for #\<#Class:0x664ede8:0x664edc0\>

Any idea how to fix this? The hyphens are dictated by the client,  
thus I can’t change that.

Thanks,  
Jeff

---

<div class="post-metadata">

**Author:** ![jjudge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ebca7d/32.png) [@jjudge](https://www.ruby-forum.com/u/jjudge)\
**Post date:** [March 26, 2007, 8:17am UTC](https://www.ruby-forum.com/t/issue-generating-xml-with-hyphenated-element-names/90123/2 "2007-03-26T08:17:03Z")

</div>

jjudge wrote:

> xml.street-address(p.street\_address)

> > x = Builder::XmlMarkup.new;nil  
> > =\> nil  
> > x.tag!(‘a-b’)  
> > =\> “”

That’s in one of the Pragmatic books IIRC.

–  
Phlip  
["Pigleg too?", week 1](http://flea.sourceforge.net/PiglegToo_1.html)

---

<div class="post-metadata">

**Author:** ![jjudge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ebca7d/32.png) [@jjudge](https://www.ruby-forum.com/u/jjudge)\
**Post date:** [March 26, 2007, 3:03pm UTC](https://www.ruby-forum.com/t/issue-generating-xml-with-hyphenated-element-names/90123/3 "2007-03-26T15:03:58Z")

</div>

Thanks, that worked. To show the data within the element, use:

xml.tag!(“street-address”, p.street\_address)
