# Xml question

**URL:** <https://www.ruby-forum.com/t/xml-question/184923>\
**Category:** Rails\
**Created:** [March 10, 2010, 2:16pm UTC](https://www.ruby-forum.com/t/xml-question/184923 "2010-03-10T14:16:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [March 10, 2010, 2:16pm UTC](https://www.ruby-forum.com/t/xml-question/184923/1 "2010-03-10T14:16:06Z")

</div>

Hi People,

Does anyone know what the correct way of setting an attribute for an xml  
element is? I know how to do it, but once I try to pass data to it, it  
shows up as an empty element in de outputted xml.

What I have now is the following:

xml.InstdAmt(“Ccy” =\> “EUR”) {invoice.sum\_after\_tax}

Which outputs:

I know for sure the data is there, because when I remove the setting of  
the attribute it turns up.

Many thanks,

Danny

---

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [March 10, 2010, 3:54pm UTC](https://www.ruby-forum.com/t/xml-question/184923/2 "2010-03-10T15:54:20Z")

</div>

Nobody Else wrote:

> Does anyone know what the correct way of setting an attribute for an xml  
> element is? I know how to do it, but once I try to pass data to it, it  
> shows up as an empty element in de outputted xml.
> 
> What I have now is the following:
> 
> xml.InstdAmt(“Ccy” =\> “EUR”) {invoice.sum\_after\_tax}
> 
> Which outputs:

The block is for adding child elements to an element.

Try this instead:

xml.InstdAmt({ “Ccy” =\> “EUR” }, invoice.sum\_after\_tax)

So if, for example the above element was a child of a root element you  
might have something like:

xml.RootElement do  
xml.InstdAmt({ “Ccy” =\> “EUR” }, invoice.sum\_after\_tax)  
end

Notice that the block is used to add the child element, which has an  
attribute arg (a hash) and a value arg (element contents).

---

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [March 10, 2010, 4:30pm UTC](https://www.ruby-forum.com/t/xml-question/184923/3 "2010-03-10T16:30:26Z")

</div>

That works 🙂
