Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate elements in soapbody #45

Closed
jduhamel opened this issue Mar 7, 2010 · 5 comments
Closed

Duplicate elements in soapbody #45

jduhamel opened this issue Mar 7, 2010 · 5 comments

Comments

@jduhamel
Copy link

jduhamel commented Mar 7, 2010

Hi, Thanks for the help earlier. I'm trying to figure out how to get the soap body to handle duplicate elements. like.

 <createAccount> 
   <param>newuser@domain.dom</param> 
   <key>TextMailbox</key> 
   <param> 
     <subKey key="RealName">John Doe</subKey> 
     <subKey key="Password">soappass</subKey> 
   </param> 
 </createAccount> 

I find it's difficult to get duplicate param's inserted since it's a hash. Should I do this manually?

-Joe

@rubiii
Copy link
Contributor

rubiii commented Mar 7, 2010

hey joe,

you can use arrays for duplicate elements. it's very natural. for example:

{ :key => "TextMailbox",
  :param => [
    "newuser@domain.com",
    { :subKey => ["John Doe", "soappass"]}
  ]
}

but there's a problem with the attributes of your subKey tags. normally to assign attributes to hash values, you could do:

{ :subKey => "John Doe", :attributes! => { :subKey => { :key => "RealName" } } }
# translation: <subKey key="RealName">John Doe</subKey>

currently i fear this doesn't work for duplicate elements and i'm already thinking about how this could be fixed. for now, you could use builder to do something like:

xml = Builder::XmlMarkup.new
xml.tag! :subKey, { :key => "RealName" }, "John Doe"
xml.tag! :subKey, { :key => "Password" }, "soappass"

{ :key => "TextMailbox",
  :param => [
    "newuser@domain.com",
    xml.target!
  ]
}

btw. you can experiment with this by calling to_soap_xml on a hash (try irb). it's a core extension that comes with savon.

@rubiii
Copy link
Contributor

rubiii commented Mar 11, 2010

added support for this to the dev branch: http://github.com/rubiii/savon/commit/e8dd4fea1d8ab4d0d451fdfa254960c9a749b921

with the next release, you will be able to do:

{ :key => "TextMailbox",
  :param => [
    "newuser@domain.com",
    { :subKey => ["John Doe", "soappass"],
      :attributes! => { :subKey => { :key => ["RealName", "Password"] } } }
  ]
}

this will give you the exact same xml as in your original message.

@rubiii
Copy link
Contributor

rubiii commented Mar 21, 2010

released version 0.7.6 containg a fix for this problem. please update.

calamitas pushed a commit to calamitas/savon that referenced this issue Jun 7, 2011
@mur-wtag
Copy link

+1 @rubiii

@anbublacky
Copy link

I have the same problem with the array value, but inside array again i need to pass in the hash value which again gets over written

result = client.call(:sales_order_list, message: {
	sessionId: session.body[:login_response][:login_return], 
	filters: {filter: 
				{
					item: 
						{key: 'created_at', value: 
							{key: 'from', value: '2016-12-27 00:00:00'}
					}, 
					item: {key: 'created_at', value: 
						{key: 'to', value: '2016-12-27 23:59:59'}
					} 
				}
			}
		})

I tried item inside array still gets overwritten, how do i solve this?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants