simplexml_load_file does not return any records

1

I have the following routine for reading XML file:

    $arquivo_geral = "xml_categ_1.xml";
    if (file_exists($arquivo_geral)) {
        $xml = simplexml_load_file($arquivo_geral);
        foreach($xml->categoria as $categoria):
            $idcat  = $categoria->id;
            $tipo   = $categoria->tipo;
            $categ  = trim($categoria->categ);
            $status = $categoria->status;

            echo $categ . "<br>";
        endforeach;
    } else {
        echo "Arquivo " . $arquivo_geral . " não encontrado...";
        exit();
    }

The read XML file is as follows:

    <?xml version='1.0' encoding='UTF-8'?>
    <categoria>
        <id>1</id>
        <tipo>D</tipo>
        <categ>CATEGORIA</categ>
        <status>I</status>
    </categoria>

The problem is that the read log does not appear. The file exists, print_r ($ xml), shows the following:

    SimpleXMLElement Object ( [id] => 1 [tipo] => D [categ] => CATEGORIA [status] => I )

The curious thing is that I use the same way in another routine to read other XML files and it works there. Does anyone have a clue what it can be? Thank you.

    
asked by anonymous 18.07.2017 / 19:16

0 answers