___ ___ erkimt Error generating XML ______ qstntxt ___

I made a system in PHP to display XML file, but is giving the following error:

This page contains the Following Errors: error on line 29 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error.

(A picture for you to see that even what is the bench he brings me):

Myindex.phpfile:

%pre%

Myconfig.phpfile:

%pre%

Myconexao.phpfile:

%pre%    
_________azszpr349229

As the very description of error states, you are inserting extra others information after creating the XML from the line %code% .

To parse the XML correctly, remove all of the line is %code% down. If you remove the line% %code% the error disappears, but you will result in a normal HTML page (although invalid).

    

___
1

I made a system in PHP to display XML file, but is giving the following error:

This page contains the Following Errors: error on line 29 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error.

(A picture for you to see that even what is the bench he brings me):

Myindex.phpfile:

<?phpinclude("config.php");
    include("conexao.php");

    $sql = 'select id, descricao, margem, custo, estoque from produtos';

    $resultado = mysqli_query(DBConnect(), $sql) or die (mysqli_error(DBConnect()));

    $xml = new DOMDocument('1.0', 'UTF-8');
    $xml->preserveWhiteSpace = false;
    $xml->formatOutput = true;

    $produtos = $xml->createElement('Produtos');

    while($dados = mysqli_fetch_object($resultado))
    {
        $item = $xml->createElement('Item');
        $descricao = $xml->createElement('descricao', $dados->descricao);
        $margem = $xml->createElement('margem', $dados->margem);
        $custo = $xml->createElement('custo', $dados->custo);
        $estoque = $xml->createElement('estoque', $dados->estoque);

        $item->appendChild($descricao);
        $item->appendChild($margem);
        $item->appendChild($custo);
        $item->appendChild($estoque);

        $produtos->appendChild($item);
    }

    $xml->appendChild($produtos);

    header('content-type: text/xml');
    print $xml->saveXML();

?>

<!DOCTYPE html>
<html>

    <head>

        <title> Testando conexão </title>

    </head>

    <body>

        <?php 

            $teste = DBConnect();

            if($teste)
            {
                echo "Conectado com sucesso!";
            }
            else
            {
                echo "Conexão falhou!";
            }

        ?>

    </body>

</html>

My config.php file:

<?php

    define('HOSTNAME', '127.0.0.1');
    define('USERNAME', 'root');
    define('PASSWORD', null);
    define('DATABASE', 'cadastro');
    define('CHARSET' , 'utf8');

?>

My conexao.php file:

<?php

    function DBConnect()
    {
        $sql = mysqli_connect(HOSTNAME, USERNAME, PASSWORD, DATABASE) or die(mysqli_error());
        mysqli_set_charset($sql, CHARSET) or die(mysqli_error($sql));

        return $sql;
    }

?>
    
asked by anonymous 10.12.2018 / 20:55

1 answer

1
___ ___ erkimt Error generating XML ______ qstntxt ___

I made a system in PHP to display XML file, but is giving the following error:

This page contains the Following Errors: error on line 29 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error.

(A picture for you to see that even what is the bench he brings me):

Myindex.phpfile:

%pre%

Myconfig.phpfile:

%pre%

Myconexao.phpfile:

%pre%    
_________azszpr349229

As the very description of error states, you are inserting extra others information after creating the XML from the line <!DOCTYPE html> .

To parse the XML correctly, remove all of the line is <!DOCTYPE html> down. If you remove the line% header('content-type: text/xml'); the error disappears, but you will result in a normal HTML page (although invalid).

    
___
11.12.2018 / 00:37