Problem in pairing Web Service response

2

I have not been able to receive the answer given to me by a Web Service for several days; My code is as follows:

      <?php 
         $params = array('NitProveedor' => '860000896',
                'baseDatos' => '1',
                'FechaInicial' => '01/04/2016',
                'FechaFinal' => '01/05/2016',
                'numeroFacutura' => 'BO-00019421');
$wsdl = 'http://10.1.1.26:82/SincoConinsaRH_PRBINT/ERPNET/Financiero/Comunicaciones/CuentasPorPagar/ExtratoProveedor/ExtractoProveedorService.svc?wsdl';

$options = array(
        'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
        'style'=>SOAP_RPC,
        'use'=>SOAP_ENCODED,
        'soap_version'=>SOAP_1_1,
        'cache_wsdl'=>WSDL_CACHE_NONE,
        'connection_timeout'=>6000,
        'trace'=>true,
        'encoding'=>'UTF-8',
        'exceptions'=>true,
    );
try {
    $soap = new SoapClient($wsdl, $options);
    $data = $soap->ExtratoProveedor($params);
    $xmlstring = $soap->__getLastResponse();

}
catch(Exception $e) {
    die($e->getMessage());
}

die;

The answer that returns the __getLastResponse() if I do one:

echo $xmlstring = $soap->__getLastResponse();

Show me:

  

200132625BO-0001942101/04 / 2016860000896Other (Ch. Ger. - Carta) 24575000.003932000.000.000.000.000.000.000.0028507000.000.0028507000.000.000.00CENTRO COMERCIAL DIVERPLAZA -BOG

It's like the answer in a string does not include it as an array. If I right click to see source code it shows a kind of XML that looks like this:

<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>
<s:Body><ExtratoProveedorResponse xmlns='ERPNet/Financiero/Comunicaciones/CuentasPorPagar/ExtratoProveedor'><ExtratoProveedorResult><Facturas xmlns=''>
<Factura>
<NumeroCE>200132625</NumeroCE>
<FacturaProv>BO-00019421</FacturaProv>
<FechaPago>01/04/2016</FechaPago>
<Nit>860000896</Nit>
<FormaGiro>Otros (Ch. Ger. - Carta)</FormaGiro>
<ChequeNo></ChequeNo>
<Banco></Banco>
<TipoCuentaBancaria></TipoCuentaBancaria>
<CuentaBancariaNo></CuentaBancariaNo
><SubTotal>24575000.00</SubTotal>
<Iva>3932000.00</Iva>
<ReteIca>0.00</ReteIca>
<ReteIva>0.00</ReteIva>
<ReteFuente>0.00</ReteFuente>
<ReteGarantia>0.00</ReteGarantia>
<Amortizacion>0.00</Amortizacion>
<ReteCree>0.00</ReteCree>
<Neto>28507000.00</Neto>
<DescuentosF>0.00</DescuentosF>
<Pagado>28507000.00</Pagado>
<Saldo>0.00</Saldo>
<NotasCredito>0.00</NotasCredito>
<Proyecto>CENTRO COMERCIAL DIVERPLAZA -BOG</Proyecto>
</Factura></Facturas>
</ExtratoProveedorResult></ExtratoProveedorResponse
></s:Body>
</s:Envelope>

The problem is that when I try to parsed this response with simpleXML:

$xmlString = $ws->__getLastResponse();
$xml = simplexml_load_string($xmlString);

I try to show or access $ xml does not show anything; as if the load of $ xmlString could not recognize the format it receives in the response; I've even tried this:

$xml = new SimpleXMLElement($xmlString);
print_r($xml);

and the answer you give me is this: String could not be parsed as XML

I have come to the conclusion that the XML obtained in the response is not compatible by its structure with the functionality of simpleXML so I would like to know if someone has addressed a similar problem and how it has been solved. NOTE: the WS response is type any.

    
asked by Carlos Adrian Zapata Garcia 17.08.2017 в 14:19
source

1 answer

0

I have solved it like this:

$xmlstring = $soap->__getLastResponse();
$clean_xml = str_ireplace(['s:'], '', $xmlstring);
xml = simplexml_load_string($clean_xml);

Thanks @joreldraw Now I have parsed the XML and it looks like this:

SimpleXMLElement Object
(
    [Body] => SimpleXMLElement Object
        (
            [ExtratoProveedorResponse] => SimpleXMLElement Object
                (
                    [ExtratoProveedorResult] => SimpleXMLElement Object
                        (
                            [Facturas] => SimpleXMLElement Object
                                (
                                    [Factura] => SimpleXMLElement Object
                                        (
                                            [NumeroCE] => 200132625
                                            [FacturaProv] => BO-00019421
                                            [FechaPago] => 01/04/2016
                                            [Nit] => 860000896
                                            [FormaGiro] => Otros (Ch. Ger. - Carta)
                                            [ChequeNo] => SimpleXMLElement Object
                                                (
                                                )

                                            [Banco] => SimpleXMLElement Object
                                                (
                                                )

                                            [TipoCuentaBancaria] => SimpleXMLElement Object
                                                (
                                                )

                                            [CuentaBancariaNo] => SimpleXMLElement Object
                                                (
                                                )

                                            [SubTotal] => 24575000.00
                                            [Iva] => 3932000.00
                                            [ReteIca] => 0.00
                                            [ReteIva] => 0.00
                                            [ReteFuente] => 0.00
                                            [ReteGarantia] => 0.00
                                            [Amortizacion] => 0.00
                                            [ReteCree] => 0.00
                                            [Neto] => 28507000.00
                                            [DescuentosF] => 0.00
                                            [Pagado] => 28507000.00
                                            [Saldo] => 0.00
                                            [NotasCredito] => 0.00
                                            [Proyecto] => CENTRO COMERCIAL DIVERPLAZA -BOG
                                        )
                                )
                        )
                )
        )
)
    
answered by 17.08.2017 в 15:52