Why does simplexml_load_file return only the first result?

Asked

Viewed 86 times

1

Hello I am 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 might be wrong?

To be inside a foreach should show all records, but only the first appear.

I tried to turn the file like 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 />";
 }

1 answer

0

Problem solved... I had to access by hierarchy to make it work.

Correct is ($xml->REQUESTS->REQUEST $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 />";
 }

Browser other questions tagged

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