Как вернуть XML-ответ с помощью soapserver и soapvar

Я реализовал soapserver, который генерирует xml-ответ.

Сначала у меня есть этот файл php:

<?php

class Testwebservice {
public $name;
public $value;
}function getWebservice($input1, $input2) {

$testwebservices = array();

$testwebservices[0] = new Testwebservice();
$testwebservices[0]->name = $input1->name;
$testwebservices[0]->value = $input1->value;

$testwebservices[1] = new Testwebservice();
$testwebservices[1]->name = $input2->name;
$testwebservices[1]->value = $input2->value;

/**
* Use an ArrayObject instead of a plain array.
*/
$return_array = new ArrayObject();

foreach ($testwebservices as $l) {

// Build a basic return object.
$webservice = new Testwebservice();
$webservice->name = $l->name;
$webservice->value = $l->value;

/**
* Encode each array element with SoapVar.  Parameter 5 is the name of the
* XML element you want to use.  This only seems to work within
* an ArrayObject.
*/
$webservice = new SoapVar($webservice, SOAP_ENC_OBJECT, null, null, 'return');

$return_array->append($webservice);
}
print_r($return_array);
return $return_array;
}

$url = 'testphp.local/webservice.php';
$service = new SoapServer(null, ['uri' => $url]);

$service->addFunction('getWebservice');
$service->handle();

Этот файл возвращает объект массива:

stdClass Object
(
[return] => Array
(
[0] => stdClass Object
(
[name] => input1
[value] => 100
)

[1] => stdClass Object
(
[name] => input2
[value] => 200
)
)
)

Когда я преобразую этот объект в XML, у меня есть этот ответ:

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:RequestResponse>
<ns1:return>
<ns1:return>
<ns1:name>input</ns1:name>
<ns1:value>100</ns1:value>
</ns1:return>
<ns1:return>
<ns1:name>input2</ns1:name>
<ns1:value>200</ns1:value>
</ns1:return>
</ns1:return>
</ns1:RequestResponse>
</soapenv:Body>
</soapenv:Envelope>

Моя проблема в том, что я хотел бы удалить первый тег возврата, чтобы я мог получить ответ XML, как это:

    <?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:RequestResponse>
<ns1:return>
<ns1:name>input</ns1:name>
<ns1:value>100</ns1:value>
</ns1:return>
<ns1:return>
<ns1:name>input2</ns1:name>
<ns1:value>200</ns1:value>
</ns1:return>
</ns1:RequestResponse>
</soapenv:Body>
</soapenv:Envelope>

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …