試圖解析這個SOAP響應,但XPath的()將返回
調試警告:的SimpleXMLElement :: XPath的()未定義命名空間前綴 調試警告:的SimpleXMLElement :: XPath的()評估失敗
$result = '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<env:Body xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<v4:TrackReply xmlns:v4="http://fedex.com/ws/track/v4">
...
</v4:TrackReply>
</env:Body>
</soapenv:Envelope>';
$xml = simplexml_load_string($result,NULL,NULL,'http://schemas.xmlsoap.org/soap/envelope/');
foreach($xml->xpath('env:Body') as $body){
//drill down here...
}
通過調用registerXPathNamespace()我能夠進入我的foreach循環,因爲$ xml-> xpath('env:Body')現在創建一個空的SimpleXMLElement對象 – Slinky
@Slinky查看更新的答案 - SimpleXMLElement對象看起來是空的,但實際上包含我看到的信息 –
。這有助於很多。謝謝 – Slinky