simplexml_load_file does not return any record

Asked

Viewed 76 times

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 record does not appear. The existing file, 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 there it works. Does anyone have a hint of what it might be ? Thank you.

No answers

Browser other questions tagged

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