在 Savon 如何根据元素数量创建标签数组item_id
?这个还有什么办法吗?
item_id = "abc, def, xyz"
n = item_id.split(,).length
#ItemList shall be of n times by creating ItemList for each
soap.body = {
'Body' => {
'ItemList' => {
'ItemId' => "abc"
}
'ItemList' => {
'ItemId' => "def"
}
'ItemList' => {
'ItemId' => "xyz"
}
}
}
编辑:下面是实际预期 xml 的示例,每个 .xmlBody
应有多个ItemList
值标签ItemId
。ItemId
长度可以是任何东西。
item_id = "abc, def, xyz" #split this and make xml for each item.
<Body>
<ItemList>
<ItemId>abc</ItemId> #abc
<TimeStamp>
<Time>04:57:40</Time>
<TimeZone>EST</TimeZone>
<Date>2012-05-12</Date>
</TimeStamp>
<ContactInfo>
<Phone>888-888-8880</Phone>
<Email>somebody1@somewhere.com</Email>
<Name>name1</Name>
</ContactInfo>
</ItemList>
<ItemList>
<ItemId>def</ItemId> #def
<TimeStamp>
<Time>04:27:40</Time>
<TimeZone>EST</TimeZone>
<Date>2012-05-12</Date>
</TimeStamp>
<ContactInfo>
<Phone>888-888-8881</Phone>
<Email>somebody2@somewhere.com</Email>
<Name>name2</Name>
</ContactInfo>
</ItemList>
<ItemList>
<ItemId>xyz</ItemId> #xyz
<TimeStamp>
<Time>04:37:40</Time>
<TimeZone>EST</TimeZone>
<Date>2012-05-12</Date>
</TimeStamp>
<ContactInfo>
<Phone>888-888-8882</Phone>
<Email>somebody2@somewhere.com</Email>
<Name>name3</Name>
</ContactInfo>
</ItemList>
</Body>