我正在使用萨文。动态生成多个 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"
}
}
}