可以使用前面的方法的组合轻松地将以下SOAP响应结构转换为数组。 在某些情况下,仅使用函数“ simplexml_load_string”除去冒号“:”即可返回null。
SOAP响应
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
xmlns:ns2="http://ws.iatai.com/">
94567
3958
3
Declinada
202
93815.0
86815.0
0.0
COP
24-07-2015 12:18:40 PM
REJECT
1
VISA
411111
1111
3
PHP转换:
$response = preg_replace("/(]*>)/", "$1$2$3", $response);
$xml = new SimpleXMLElement($response);
$body = $xml->xpath('//SBody')[0];
$array = json_decode(json_encode((array)$body), TRUE);
print_r($array);
结果:
Array
(
[ns2transaccionResponse] => Array
(
[respuestaTransaccion] => Array
(
[idTransaccion] => 94567
[referencia] => 3958
[idEstado] => 3
[nombreEstado] => Declinada
[codigoRespuesta] => 202
[valor] => 93815.0
[iva] => 86815.0
[baseDevolucion] => 0.0
[isoMoneda] => COP
[fechaProcesamiento] => 24-07-2015 12:18:40 PM
[mensaje] => REJECT
[tarjetaRespuesta] => Array
(
[idFranquicia] => 1
[nombreFranquicia] => VISA
[numeroBin] => 411111
[numeroProducto] => 1111
)
[procesadorRespuesta] => Array
(
[idProcesador] => 3
)
)
)
)