使用PHP SOAPclient将键值XML转换为其他格式


Transform key-value XML into other format with PHP SOAPclient?

我想将SOAP请求从键值格式转换为另一种格式:

  <SOAP-ENV:Header>
    <ns2:AUTH>
      <item>
        <key>username</key>
        <value>testuser</value>
      </item>
      <item>
       <key>password</key>
        <value>xxxxx</value>
      </item>
    </ns2:AUTH>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <ns1:getProductConfig/>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope> 

这就是我想要的:

  <SOAP-ENV:Header>
    <ns2:AUTH>
        <username>testuser</username>
        <password>xxxxx</password>
    </ns2:AUTH>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <ns1:getProductConfig>
          <partner_id>1</partner_id>
    </ns1:getProductConfig>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是我的PHP代码,我在其中创建了一个新的SoapClient对象:

$header = new SoapHeader('chainstore-api','AUTH',$headerOptions, FALSE);
$req = new SoapClient(NULL, $options);
$req->__setSoapHeaders($header);
$res = $req->getProductConfig($params);
echo $res;

PS:目前,它是非wsdl样式,但我也在考虑更改为使用wsdl。

这听起来可能很疯狂,但我只是通过使用WSDL来解决这个问题。

这要容易得多。WSDL文件将确定SOAP请求和响应。