解析SOAP响应

问题描述 投票:0回答:1

我已经花了数小时试图解析我无法控制的SOAP响应。我尝试了很多在SO上发现的方法,但是都没有运气。

这是我从边缘浏览器获得的响应正文:

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:gXMLQueryResponse xmlns:ns1="urn:com-photomask-feconnect-IFeConnect" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:string">&lt;?xml version = &apos;1.0&apos; encoding = &apos;UTF-8&apos;?&gt;
&lt;ROWSET&gt;
   &lt;ROW num=&quot;1&quot;&gt;
      &lt;CUSTOMER_NAME&gt;HITACHI&lt;/CUSTOMER_NAME&gt;
   &lt;/ROW&gt;
&lt;/ROWSET&gt;
</return>
</ns1:gXMLQueryResponse>

</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我正在尝试获取CUSTOMER_NAME的值。

这是我使用的代码:


$client = new SoapClient($urla, array('trace' => 1));

try {
    $result = $client->__soapCall("gXMLQuery", $params);

    $response = ($client->__getLastResponse());

    $xml = simplexml_load_string($response);


    $rows = $xml->children('SOAP-ENV', true)->Body->children('ns1', true)->gXMLQueryResponse->return->ROWSET->ROW;

    foreach ($rows as $row)
    {
        $customer = $row->CUSTOMER_NAME;
        echo $customer;

    }



} catch (SoapFault $e) {


}
php soap simplexml
1个回答
0
投票

return是一个字符串,需要首先解析它,然后才能使用SimpleXML访问它。

© www.soinside.com 2019 - 2024. All rights reserved.