xml builder not able to create namespaced elements w/attributes??

Discussion in 'Ruby' started by Stephen Bannasch, Jul 23, 2006.

  1. I'd like to be able to build a xm like this with builder:

    <sailuserdata:ESession xmi:version="2.0" xmlns:xmi="http://
    www.omg.org/XMI" xmlns:sailuserdata="sailuserdata">
    <mydata/>
    </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/):

    x.sailuserdata :ESession
    => "<sailuserdata:ESession/>"

    And I can wrap my own elements easily:

    x.sailuserdata :ESession do
    x.mydata
    end
    => "<sailuserdata:ESession><mydata/></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
     
    Stephen Bannasch, Jul 23, 2006
    #1
    1. Advertising

  2. Stephen Bannasch

    Guest

    Hi --

    On Sun, 23 Jul 2006, Stephen Bannasch wrote:

    > I'd like to be able to build a xm like this with builder:
    >
    > <sailuserdata:ESession xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
    > xmlns:sailuserdata="sailuserdata">
    > <mydata/>
    > </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/):
    >
    > x.sailuserdata :ESession
    > => "<sailuserdata:ESession/>"
    >
    > And I can wrap my own elements easily:
    >
    > x.sailuserdata :ESession do
    > x.mydata
    > end
    > => "<sailuserdata:ESession><mydata/></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?


    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

    --
    http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
    http://www.manning.com/black => RUBY FOR RAILS (reviewed on
    Slashdot, 7/12/2006!)
    http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log
    => me
     
    , Jul 23, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason
    Replies:
    2
    Views:
    634
    Jason
    Apr 28, 2007
  2. Arunprabu Durairaju

    Builder gem - xml attributes ordering

    Arunprabu Durairaju, Jun 7, 2007, in forum: Ruby
    Replies:
    5
    Views:
    187
    Keith Fahlgren
    Jun 7, 2007
  3. sed_y
    Replies:
    0
    Views:
    1,025
    sed_y
    Feb 15, 2012
  4. andyashton
    Replies:
    3
    Views:
    130
    Martin Honnen
    Jul 6, 2007
  5. Replies:
    0
    Views:
    167
Loading...

Share This Page