How to set attributes on elements of the same name?

124 views
Skip to first unread message

Ryan Grimard

unread,
Sep 11, 2012, 8:19:54 AM9/11/12
to sav...@googlegroups.com
I'm constructing the soap body using the hash syntax.  I need to set an attribute on elements of the same name.  With the following code, I end up with a single "value" element with attrx set to bar.

# need this:  ..... <PropertyValues><value attrx="foo">0003</value><value attrx=bar></value></PropertyValues>...

soap.body = {"element1" =>
                       {"element2" =>
                            {"element3" => "xyz"
                             "element4" => some_data,
                             "element5" =>
                                 {
                                     "ID" => "3",
                                     "PropertyValues" =>
                                         {
                                             "value" => "0003",
                                             :attributes! => {"value" => {"attrx" => "foo"}},
                                             "value" => "",
                                             :attributes! => {"value" => {"attrx" => "bar"}},
                                         }
                                 }
                            },
                       }
      }
    end

rubiii

unread,
Feb 7, 2013, 8:40:10 AM2/7/13
to sav...@googlegroups.com, bl...@getabine.com
arrays with attributes are a little difficult to get right, but it works the same in 1.x and 2.x.
here's an example (savon 2.x):

    message = {
      'PropertyValues' => {
        'value' => ['003', '004'],
        :attributes! => { 'value' => { 'attrx' => ['foo', 'bar'] } },
      }
    }

    client = Savon.client(
      endpoint: 'http://example.com',
      namespace: 'http://v1.example.com'
    )

    client.call(:whatever, message: message)

    # <env:Body>
    #   <wsdl:whatever>
    #    <PropertyValues>
    #      <value attrx="foo">003</value>
    #       <value attrx="bar">004</value>
    #     </PropertyValues>
    #   </wsdl:whatever>
    # </env:Body>

hope that helps!

cheers,
daniel

barber...@gmail.com

unread,
Jan 18, 2014, 7:45:39 PM1/18/14
to sav...@googlegroups.com, bl...@getabine.com
What about in version 2.3? It doesn't seem to work.

In version 2.1 generated this 

      <env:Body>
        <tns:CreateRequest>
          <tns:Objects xsi:type="tns:Subscriber">
            <tns:EmailAddress>CreatedS...@test.com</tns:EmailAddress>
          </tns:Objects>
        </tns:CreateRequest>
      </env:Body>
    </env:Envelope>

Now in version 2.3 using the same hash

      <env:Body>
      <tns:CreateRequest>
        <tns:Objects>
          <tns:EmailAddress>CreatedS...@test.com</tns:EmailAddress>
        </tns:Objects>
        <tns:attributes>
          <tns:Objects><xsi:type>tns:Subscriber</xsi:type></tns:Objects>
        </tns:attributes>
      </tns:CreateRequest>
    </env:Body>

Which is not working with the service.

Thanks
Reply all
Reply to author
Forward
0 new messages