Last Updated: February 25, 2016
· billwatts

Adding attributes to an input tag with Savon

Do you hate making soap requests? Yeah, I do too, but at least Savon eases the pain. Savon, in my opinion, is easily the best gem out there for making soap requests, but there was a hangup that I'd like to share. When trying to contact a wsdl, the wsdl kept returning an error that it was looking for an input tag with a specific attribute. The wsdl was looking for something like this...

<AnAction xmlns="" />

It took me a few minutes to figure out, but this is the result...

soap_client = Savon.client("")

response = soap_client.request "AnAction" do
  http.headers["soapAction"] = "AnAction"
  soap.input = ["AnAction", {"xmlns" => ""}]
  soap.body = {
    "SomeAttribute" => "SomeValue"

Which would give you something like this...

    <AnAction xmlns="" />

There you have it, if you need an attribute on the input tag, you know how to do it.

2 Responses
Add your response

How can apply this to Savon 2.5.1... this this mi code...

request = { :ApiKey=> safetypayapikey,
:RequestDateTime=> requestdate,
:Language => language,
response = :create
:message => request).body[:customtransactionresponse]

I need add to "Language" node the namespace: xmlns="urn:safetypay:messages:mws:api"


over 1 year ago ·

To SAVON 2.51. I need this:

<Language xmlns="urn:safetypay:schema:mws:api">ES</Language>

In Ruby:

:Language => {
:@xmlns => "urn:safetypay:schema:mws:api",
:content! => language

Some suggestion?

over 1 year ago ·