我從web服務響應:SOAP響應 - 在php中解析xml,如何訪問?
<?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>
我如何可以訪問元素時間或狀態在BOGUS[0]
或BOGUS[1]
?
我嘗試這樣做:
$soap = simplexml_load_string($str);
$response = $soap->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('http://tempuri.org/')->H1;
$time = $response->BOGUS[1]->time;
echo $time;
,但它不工作。返回:注意:試圖獲取非對象的屬性
tempuri.org是正確的。我在xmlgrid.net上粘貼了xml響應並獲得了正確的樹。
** HTTP://tempuri.org/**是正確的?此外,你應該解釋你的意思,但它不是working_。 – CSchulz 2014-09-29 08:41:09
是的,tempuri.org是正確的。代碼:$ time = $ response-> BOGUS [1] - > time;返回:注意:試圖獲取非對象的屬性 – scyche 2014-09-29 09:27:40
您應該添加有關您的問題的信息,作爲編輯您的問題而不是評論。 :) – CSchulz 2014-09-29 09:36:59