# Don't show XML attributes if they ar eblank or nil

**URL:** <https://www.ruby-forum.com/t/dont-show-xml-attributes-if-they-ar-eblank-or-nil/173208>\
**Category:** Rails\
**Created:** [August 4, 2009, 11:20pm UTC](https://www.ruby-forum.com/t/dont-show-xml-attributes-if-they-ar-eblank-or-nil/173208 "2009-08-04T23:20:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bikle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9e8a1a/32.png) [@bikle](https://www.ruby-forum.com/u/bikle)\
**Post date:** [August 4, 2009, 11:20pm UTC](https://www.ruby-forum.com/t/dont-show-xml-attributes-if-they-ar-eblank-or-nil/173208/1 "2009-08-04T23:20:43Z")

</div>

Hi, I’m creating a dynamic xml file using builder in Rails, which pulls  
from several different related tables. Some of my nodes include  
attributes, but some don’t. I would like to find a way to leave out  
those attributes that are blank.

My XML now:  
  
Vermont   
27%

Hawaii 100%

should look like this:  
  
Vermont   
27%

Hawaii 100%

without the blank type="" attribute.

My .builder includes this:

@table.each do |r|  
xml.row(:line =\> r[0], :type=\> r[1]) do  
r.each do |i|  
xml.cell(i, :column\_id =\> ‘’)  
end  
end  
end

I can make the value for :type =\> nil, but I still get the blank  
attribute. I tried conditionals inside the node, but that didn’t work.  
Any ideas?

Thanks.
