Ruby - Rails - Structure SOAP XML body

ArTanGeL

New Member
I am using Savon. What is a right way to dynamically generate multiple SOAP body XML tags? I am thinking of this way, which isn't the right way to do it. \[code\]item_id = "abc,def,xyz"item_xml = ""item_id.split(",").each do |e|item_xml << 'ItemId' => "#{e}" #Sure this is a wrong wayendbeginmyclient = Savon::Client.new do |wsdl, soap|wsdl.document = "http://somthing.com/service?wsdl"wsdl.soap_actionsendresult = myclient.request :v1, :update do |soap|soap.namespaces["xmlns:v1"] = "http://somthing.com/service?wsdl"end#This is how I do for manual single entry of ItemIdsoap.body = {'Body' => { 'ItemList' => {'ItemId' => "abc123" } }}#Want to generate soap body with multiple ItemIdsoap.body = {'Body' => { 'ItemList' => {item_xml #shall be equivalent as this #'ItemId' => "abc",#'ItemId' => "def",#'ItemId' => "xyz" } }}\[/code\]EDIT:How about creating an array of tags based on number of elements in \[code\]item_id\[/code\]? \[code\]item_id = "abc, def, xyz"n = item_id.split(,).length #shall be equivalent as this #ItemList shall be of n timessoap.body = { 'Body' => { 'ItemList' => { 'ItemId' => "abc" } 'ItemList' => { 'ItemId' => "def" } 'ItemList' => { 'ItemId' => "xyz" } } }\[/code\]
 
Back
Top