When importing an xml file it is coming in white

0

I've created this following xml file:

<?xml version="1.0" encoding="UTF-8"?>
<usuarios>
    <usuario>
        <nome>Andrêy Ferraz</nome>
        <idade>25</idade>
    </usuario>
    <usuario>
        <nome>Carlos Meira</nome>
        <idade>30</idade>
    </usuario>
    <usuario>
        <nome>Fernando Amarelo</nome>
        <idade>40</idade>
    </usuario>
    <usuario>
        <nome>Carlos Santos</nome>
        <idade>50</idade>
    </usuario>
    <usuario>
        <nome>Jose Santana</nome>
        <idade>78</idade>
    </usuario>
    <usuario>
        <nome>Marcus Santos</nome>
        <idade>56</idade>
    </usuario>
    <usuario>
        <nome>Jose Ferreira</nome>
        <idade>67</idade>
    </usuario>
    <usuario>
        <nome>Wallatas Silva</nome>
        <idade>78</idade>
    </usuario>
    <usuario>
        <nome>Marcus Vieira</nome>
        <idade>34</idade>
    </usuario>
</usuarios>

Here I created a case that allowed you to import this file and identify your location on my server:

case"importar"; //importando arquivo xml
            importarUsuario ($conexao, "usuario/_usuarios.xml");
            break;

Here I run the function and try to print the file on the screen:

function importarUsuario ($conexao, $arquivosXml){

    $xml = simplexml_load_file($arquivosXml);
    print_r($xml);  

So you're returning all blank, would someone please show you where my error is ??

    
asked by anonymous 14.04.2017 / 05:47

2 answers

1

With the code snippets shown there is no error. Putting everything in a file (except xml) and passing the right condition to the switch, everything works. See:

<?php
$condicao = 'importar';
$conexao = null;

switch($condicao){
    case "importar"; //importando arquivo xml
            importarUsuario ($conexao, "c.xml");
        break;
}

function importarUsuario ($conexao, $arquivosXml){
    $x = simplexml_load_file('c.xml');
    print_r($x);
}
?>

The above code prints:

SimpleXMLElement Object ( [usuario] => Array ( [0] => SimpleXMLElement Object ( [nome] => Andrêy Ferraz [idade] => 25 ) [1] => SimpleXMLElement Object ( [nome] => Carlos Meira [idade] => 30 ) [2] => SimpleXMLElement Object ( [nome] => Fernando Amarelo [idade] => 40 ) [3] => SimpleXMLElement Object ( [nome] => Carlos Santos [idade] => 50 ) [4] => SimpleXMLElement Object ( [nome] => Jose Santana [idade] => 78 ) [5] => SimpleXMLElement Object ( [nome] => Marcus Santos [idade] => 56 ) [6] => SimpleXMLElement Object ( [nome] => Jose Ferreira [idade] => 67 ) [7] => SimpleXMLElement Object ( [nome] => Wallatas Silva [idade] => 78 ) [8] => SimpleXMLElement Object ( [nome] => Marcus Vieira [idade] => 34 ) ) ) 
    
14.04.2017 / 06:31
0

For the solution I did the following in the case:

case"importar"; //importando arquivo xml
            importarUsuario ($conexao);
            break;

And in the function I had to do as follows:

function importarUsuario ($conexao){

    $xml = simplexml_load_file('_usuarios.xml');
    print_r($xml);

In this way avoided to appear all white, I honestly did not understand why this occurred, it would perhaps be due to the fact it gave this using version 7 of PHP, I think not right?     

14.04.2017 / 06:56