XML only brings empty value

1

I have xml down brought from a cUrl .

<DistanceMatrixResponse>
<status>OK</status>
<origin_address>Muriaé - MG, 36880-000, Brasil</origin_address>
<destination_address>Patrocínio do Muriaé - MG, 36860-000, Brasil</destination_address>
<row>
<element>
<status>OK</status>
<duration>
<value>3939</value>
<text>1 hora 6 minutos</text>
</duration>
<distance>
<value>43371</value>
<text>43,4 km</text>
</distance>
</element>
</row>
</DistanceMatrixResponse>

I'm trying to read the status in the following ways, but it's just empty.

When I give a print_r (), it reads all the xml on the screen.

 $frete = new CalculaFrete(36880000, 36860000);
 $freteXML1 = $frete->calculaFrete2();
 $freteXML2 = simplexml_load_file($frete->calculaFrete2());
 print "<pre>";
 print_r($freteXML1);
 print $freteXML1->row->element->status;
 print $freteXML2->row->element->status;
 print "</pre>";

Where am I going wrong?

    
asked by anonymous 16.10.2016 / 21:35

1 answer

2

In this $xml I did the test and it worked, but it was used simplexml_load_string because a text with xml is returned by the method.

$xml = '<DistanceMatrixResponse>
<status>OK</status>
<origin_address>Muriaé - MG, 36880-000, Brasil</origin_address>
<destination_address>Patrocínio do Muriaé - MG, 36860-000, Brasil</destination_address>
<row>
<element>
<status>OK</status>
<duration>
<value>3939</value>
<text>1 hora 6 minutos</text>
</duration>
<distance>
<value>43371</value>
<text>43,4 km</text>
</distance>
</element>
</row>
</DistanceMatrixResponse>';

$obj = simplexml_load_string($xml);

print $obj->status;
print '<br />';
print $obj->row->element->status;

Example: IDEONE

    
16.10.2016 / 21:57