PHP 更改 Zendsoap 响应输出

PHP Change Zendsoap response output

当我创建 Zendsoap 服务器时,它工作正常,我得到以下输出:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost:8080/soap" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <SOAP-ENV:Body>
  <ns1:getTeacherResponse>
     <return SOAP-ENC:arrayType="ns2:Map[1]" xsi:type="SOAP-ENC:Array">
        <item xsi:type="ns2:Map">
           <item>
              <key xsi:type="xsd:string">teacherID</key>
              <value xsi:type="xsd:string">011</value>
           </item>
           <item>
              <key xsi:type="xsd:string">name</key>
              <value xsi:type="xsd:string">Miss Piggy</value>
           </item>
        </item>
     </return>
  </ns1:getTeacherResponse>

它来自我输出的以下数组:

array:1 [
  0 => array:2 [
    "teacherID" => "011"
    "name" => "Miss Piggy"
   ]
]

现在我想要这样的输出:

...
<item>
<teacherID>011</teacherID>
<name>Miss Piggy</name>
</item>
...

我如何告诉 zendsoap 如何格式化响应?

我找到了解决这个问题的方法:

    $xml = new XMLWriter();
    $xml->openMemory();

    $xml->startElementNS(null, 'teacher', NULL);

    foreach ($arr as $key=>$value){
        $xml->startElementNS(null, $key, NULL);
        $xml->Text($value);
        $xml->endElement();
    }
    $xml->endElement();


    return new SoapVar($xml->outputMemory(), XSD_ANYXML);

哪个变成正确的xml

...
<teacher>
    <teacherID>123</teacherID>
    <name>Miss Piggy</name>
</teacher>
...