# Xml builder not able to create namespaced elements w/attribu

**URL:** <https://www.ruby-forum.com/t/xml-builder-not-able-to-create-namespaced-elements-w-attribu/99505>\
**Category:** Ruby\
**Created:** [July 23, 2006, 4:29pm UTC](https://www.ruby-forum.com/t/xml-builder-not-able-to-create-namespaced-elements-w-attribu/99505 "2006-07-23T16:29:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stepheneb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@stepheneb](https://www.ruby-forum.com/u/stepheneb)\
**Post date:** [July 23, 2006, 4:29pm UTC](https://www.ruby-forum.com/t/xml-builder-not-able-to-create-namespaced-elements-w-attribu/99505/1 "2006-07-23T16:29:56Z")

</div>

I’d like to be able to build a xm like this with builder:

\<sailuserdata:ESession xmi:version=“2.0” xmlns:xmi=“http://  
[XMI](http://www.omg.org/XMI)” xmlns:sailuserdata=“sailuserdata”\>  
  
\</sailuserdata:ESession\>

XML Builder has a way of making an element with a namespace (put a  
space before the colon, see: [http://builder.rubyforge.org/](http://builder.rubyforge.org/)):

x.sailuserdata :ESession  
=\> “sailuserdata:ESession/”

And I can wrap my own elements easily:

x.sailuserdata :ESession do  
x.mydata  
end  
=\> “sailuserdata:ESession\</sailuserdata:ESession\>”

But I can’t get it to add attributes.

x.sailuserdata :ESession(“key” =\> “123”)  
SyntaxError: compile error  
(irb):49: parse error, unexpected ‘(’, expecting $  
x.sailuserdata :ESession(“key” =\> “123”)  
^  
from (irb):49  
from :0

Any ideas on how I can fix (or work around) this?

Thanks

---

<div class="post-metadata">

**Author:** ![stepheneb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@stepheneb](https://www.ruby-forum.com/u/stepheneb)\
**Post date:** [July 23, 2006, 4:39pm UTC](https://www.ruby-forum.com/t/xml-builder-not-able-to-create-namespaced-elements-w-attribu/99505/2 "2006-07-23T16:39:30Z")

</div>

Hi –

On Sun, 23 Jul 2006, Stephen B. wrote:

> x.sailuserdata :ESession
> 
> x.sailuserdata :ESession(“key” =\> “123”)  
> SyntaxError: compile error  
> (irb):49: parse error, unexpected ‘(’, expecting $  
> x.sailuserdata :ESession(“key” =\> “123”)  
> ^  
> from (irb):49  
> from :0
> 
> Any ideas on how I can fix (or work around) this?

You have to treat the hash { “key” =\> “123” } as a second method  
argument, which is what it is. You can leave the {} off, but it still  
needs a comma before it 🙂

x.sailuserdata :ESession, “key” =\> “123”

David
