SOAP响应-在php中解析xml,如何访问?
我收到了webservice的回复:SOAP响应-在php中解析xml,如何访问?,php,xml,parsing,soap,Php,Xml,Parsing,Soap,我收到了webservice的回复: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns1:H1 xsi:type="ns1:H1">
<BOGUS>
<time>1411967345</time>
<status>1</status>
<speed>0</speed>
</BOGUS>
<BOGUS>
<time>1411964888</time>
<status>10</status>
<speed>0</speed>
</BOGUS>
</ns1:H1>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
,但它不起作用。返回:注意:尝试获取非对象的属性
tempuri.org是对的。我将xml响应粘贴到:xmlgrid.net上,得到了正确的树。您可以通过循环来完成,因为您得到的是数组作为回报
foreach ($response as $res)
{
$time = $res->BOGUS[1]->time;
echo $time;
}
我建议使用Zend Soap Client for PHP。你可以这样做:
$client = new Zend_Soap_Client("MyService.wsdl");
$result = $client->yourMethod(<YouParameters ...>);
echo $result->H1->BOGUS[1]->time;
见:
对吗?此外,你应该解释你的意思,但它不起作用。是的,tempuri.org是正确的。代码:$time=$response->伪[1]->time;返回:注意:尝试获取非object属性时,应将有关问题的信息添加为问题的编辑,而不是注释:$时间=$response->伪[1]->时间??对吗?所以变量$res是未使用的。
$client = new Zend_Soap_Client("MyService.wsdl");
$result = $client->yourMethod(<YouParameters ...>);
echo $result->H1->BOGUS[1]->time;