私はSavonを使用しています。複数のSOAP本文XMLタグを動的に生成する正しい方法は何ですか?私はこの方法を考えていますが、それは正しい方法ではありません。
item_id = "abc,def,xyz"
item_xml = ""
item_id.split(",").each do |e|
item_xml << 'ItemId' => "#{e}" #Sure this is a wrong way
end
begin
myclient = Savon::Client.new do |wsdl, soap|
wsdl.document = "http://somthing.com/service?wsdl"
wsdl.soap_actions
end
result = 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 ItemId
soap.body = {
'Body' => {
'ItemList' => {
'ItemId' => "abc123"
}
}
}
#Want to generate soap body with multiple ItemId
soap.body = {
'Body' => {
'ItemList' => {
item_xml
#shall be equivalent as this
#'ItemId' => "abc",
#'ItemId' => "def",
#'ItemId' => "xyz"
}
}
}
編集:
の要素の数に基づいてタグの配列を作成するのはどうitem_id
ですか?
item_id = "abc, def, xyz"
n = item_id.split(,).length
#shall be equivalent as this
#ItemList shall be of n times
soap.body = {
'Body' => {
'ItemList' => {
'ItemId' => "abc"
}
'ItemList' => {
'ItemId' => "def"
}
'ItemList' => {
'ItemId' => "xyz"
}
}
}