How to get xml data with php?

Asked

Viewed 1,550 times

2

I’m trying to integrate my system with the jadlog carrier but I can’t get the xml data with php.

return url of jadlog

Upshot:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
    <valorarResponse xmlns="">
        <ns1:valorarReturn xmlns:ns1="http://jadlogEdiws">
            <?xml version="1.0" encoding="utf-8" ?>
            <string xmlns="http://www.jadlog.com.br/JadlogEdiWs/services">
                <Jadlog_Valor_Frete>
                    <versao>1.0</versao>
                    <Retorno>114,11</Retorno>
                    <Mensagem>Valor do Frete</Mensagem>
                </Jadlog_Valor_Frete>
            </string>
        </ns1:valorarReturn>
    </valorarResponse>
</soapenv:Body>

I tried to get the data the following way:

$retornoJadlog= simplexml_load_string(file_get_contents($urlJadlog));

or

$retornoJadlog= simplexml_load_string($urlJadlog);

But in both ways the return is null:

object(SimpleXMLElement)#4 (0) {
}
  • Buddy, the above return is not null. It is returning the SimpleXmlElement. It is an object containing the information.

  • Possible duplicate of Check XML with php

  • How do I access the data? because using var_dump() the return is what I showed in the question

1 answer

1


See if that’s what you need boss:

<?php

$xmlDoc = new DOMDocument();
$xmlDoc->load("http://www.jadlog.com.br:8080/JadlogEdiWs/services/ValorFreteBean?method=valorar&vModalidade=5&Password=C2o0E1m3&vSeguro=N&vVlDec=100,00&vVlColeta=10,00&vCepOrig=89062080&vCepDest=89062080&vPeso=30,30&vFrap=N&vEntrega=D&vCnpj=17977285000118");

$x = $xmlDoc->documentElement;
foreach ($x->childNodes AS $item) {
  print $item->nodeName . " = " . $item->nodeValue . "<br>";
}
?>

  • Output from print_r: Simplexmlelement Object ( )

  • Peri......

  • in waiting.....

  • I was having lunch... Now I’m cool.... Thô see if I can help..... Problem is knowing exactly what you want to catch... But there goes a shot , will hit.... Take the children close...kkk POW, if I hit a validate forgets and closes the answer...vlw ;)

  • I got the boss ?

  • It worked perfectly, thank you!

  • And how to do with an xml file in a computer folder?

  • @Ulissesgimenes $xmlDoc->load('path/do/arquivo.xml')

  • I wanted to make an import of an electronic invoice xml to take the name data of the carrier and gross weight to throw this data into a receipt that I would generate and keeps giving utf8 error with utf16, have some way to solve

  • It can be a series of factors, open a question and put the code and problems.... @Ulissesgimenes

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.