问题
soapUI generates this comment Zero or more repetitions
in many places in the request XML that it builds. This is part of the XML request.
<v1:Attachments>
<!--Zero or more repetitions:-->
<v1:Attachment>
<v1:FileName>?</v1:FileName>
<v1:FileExtension>?</v1:FileExtension>
<v1:FileContents>cid:1220950351678</v1:FileContents>
</v1:Attachment>
</v1:Attachments>
I am using Savon 2.2.0 for communicating with the external service. Ruby hashes
need unique keys. I tried passing an array of hashes in the format
attachments: [{attachment:
{file_name: "foo1",
file_extension: "bar1",
file_contents:"binary_encoded_content"}},
{attachment:
{file_name: "foo2",
file_extension: "bar2",
file_contents: "binary_encoded_content"}}]
But in this case Savon just does a to_s
on the array. How can I make this work?
回答1:
attachments: {
attachment: [
{
file_name: "foo1",
file_extension: "bar1",
file_contents:"binary_encoded_content"
},
{
file_name: "foo2",
file_extension: "bar2",
file_contents: "binary_encoded_content"
}
]
}
Et voila.
来源:https://stackoverflow.com/questions/17345486/how-to-generate-repeating-xml-elements-in-savon