Duplicate tags in nusoap

I am using nusoap to connect to a soapy webservice. The Xml that the class sends to the service is built from an array, that is:

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

      

This works great. A multidimensional array also creates a nice nested XML message.

I am facing a problem where 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 element of the array overwrites the first, resulting in:

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

      

How can this be achieved?

+1


source to share


4 answers


The problem is the internal array ()

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

      

creates an array with one key ("element").



Try this and see if it works:

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

      

No guarantees though ... I have not used nusoap on long and have no PHP to test it.

+2


source


The main problem is that you are writing the wrong PHP code

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

array(1) {
  ["items"]=>
  array(1) {
    ["item"]=>
    string(7) "value 2"
  }
}

      

Which of course won't work as its synonym

 $x = array(); 
 $x['items'] = array(); 
 $x['items']['item']='value 1'; 
 $x['items']['item']='value 2'; 

      

which of course won't work.

Best bets with

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

      

and hoping that the number keys will "work", or



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

      

in case he is so inclined.

Additionally

Looking at the examples on sourceforge, this is the syntax:
$params = '<person xsi:type="tns:Person"><firstname xsi:type="xsd:string">Willi</firstname><age xsi:type="xsd:int">22</age><gender xsi:type="xsd:string">male</gender></person>';
$result = $client->call('hello', $params);

      

http: //nusoap.cvs .sourceforge.net / viewvc / checkout / nusoap / samples / wsdlclient3b.php

This example shows the use of a non- core (i.e .: numeric) array as an input source: http: //nusoap.cvs .sourceforge.net / viewvc / checkout / nusoap / samples / wsdlclient4.php

+1


source


This is weird because the method:

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

      

works with me. As explained in this link

Perhaps you need a newer version of nusoap?

+1


source


we solved this problem by passing a string instead of an array to the nusoap call function. check below link http://fundaa.com/php/solved-duplicate-tags-in-nusoap/

+1


source







All Articles