Why does simplexml_load_file only return the first result?

1

Hello, I'm trying to display the results of an XML file but it returns me only the first records, from the second record I have no more results. What could be wrong?

Being inside a foreach should show all records, but only the first ones appear.

I tried to transform the file as a string but the result was the same, simplexml_load_string($texto) only the first records were displayed.

 $xml = simplexml_load_file("arquivo.xml");
 foreach ($xml->PEDIDOS as $PEDIDOS ) {
    echo $PEDIDOS->PEDIDO->PRODUTOS->PRODUTO->PRODUTO_COD."<br /><br />";
    echo $PEDIDOS->PEDIDO->PRODUTOS->PRODUTO->PRODUTO_COD_FORNECEDOR."<br /><br />";
 }
    
asked by anonymous 29.04.2015 / 06:19

1 answer

0

Problem solved ... I had to access by hierarchy to work out.

The correct one is ($ xml- > ORDERS-> REQUEST AS $ REQUEST):

$xml = simplexml_load_file("arquivo.xml");
 foreach ($xml->PEDIDOS->PEDIDO as $PEDIDO) {
    echo $PEDIDOS->PEDIDO->PRODUTOS->PRODUTO->PRODUTO_COD."<br /><br />";
    echo $PEDIDOS->PEDIDO->PRODUTOS->PRODUTO->PRODUTO_COD_FORNECEDOR."<br /><br />";
 }
    
30.04.2015 / 00:50