2 回答

TA貢獻1824條經驗 獲得超5個贊
處理響應字符串的方法不是一個好主意,您應該堅持將內容作為XML處理并使用。這使用XPath查找處理數據的起點(我無法使用當前示例進行測試),但是應該可以幫助您完成所需的工作...
// Load the original reply
$xml = simplexml_load_string($reply);
//running through the array and printing all values
if ($xml !== false) {
// Find the <auto> element (use [0] as you want the first one)
$auto = $xml->xpath("//auto")[0];
// Loop through the cotizacion elements in the auto element
foreach ($auto->cotizacion as $cotizacion) {
foreach ($cotizacion->cobertura as $cobertura) {
echo $cobertura->codigo;
echo '<br>';
echo $cobertura->descripcion;
echo '<br>';
echo $cobertura->premio;
echo '<br>';
echo $cobertura->cuotas;
echo '<br>';
echo $cobertura->impcuotas;
echo '<br>';
}
}
}

TA貢獻1831條經驗 獲得超10個贊
SOAP響應仍然是XML文檔,因此請與其一起使用而不是與之抗爭。將其視為字符串絕對不是很好。
據我所知,您正在嘗試使用所有<cotizaction>元素。在XML文檔中查找元素很簡單。在XPath上閱讀。
$xml = simplexml_load_string(htmlspecialchars($reply));
if ($xml) {
foreach ($xml->xpath('//cotizacion') as $cotizacion) {
// do your thing
}
}
- 2 回答
- 0 關注
- 207 瀏覽
添加回答
舉報