views:

484

answers:

4

I'm using nusoap to connect to a soap webservice. The xml that the class sends to the service is constructed from an array, ie:

$params = array("param1" => "value1", "param2" => "value1");
$client->call('HelloWorld', $params, 'namespace', 'SOAPAction');

This works fine. A multidimensional array also constructs a nice nested xml message.

I encounter a problem when i need two tags with the same name:

<items>
   <item>value 1</item>
   <item>value 2</item>
</item>

$params = array("items" => array("item" => "value 1", "item" => "value 2"));

The second item in the array overwrites the first which results in:

<items>
   <item>value 2</item>
</item>

How can achieve this?

+1  A: 

The problem is with the inner array()

$test_array = array("item" => "value 1", "item" => "value 2");

creates an array with a single key ("item").

Try this and see if it works:

$params = array("items" => array("item" => array("value 1", "value 2")));

No guarantees, though... I haven't used nusoap in a long time and don't have PHP installed here to test it.

R. Bemrose
+1  A: 
Kent Fredric
A: 

No luck. It simply isn't working the way you describe. I wish it would.

array("items"=>array( "value1","value2") );

will not generate the <item> tags, and

array("items"=>array("item"=>array("value1","value2")))

returns this:

<items>

<item>Array</item>

</items>

A: 

This is strange because, method:

$params = array('items' => array('item' => array('value1', 'value2')))
$client->call( 'action', $params );

works form me. As explained in this link

Maybe you need newer version of nusoap?