Error in classxml

0

Could someone tell me how to solve this error?

Fileaccessarserver.php:

<?php$xml=simplexml_load_file("server.php?id=8");
echo $xml;

Server.php file:

<?php 
include("classxml.php");

$xml = new Xml();

$erro = 0;

$idproduto = $_GET['id'];

$xml->openTag('response');

if($idproduto=='') {

    $erro = '1';
    $msg  = 'codigo invalido!';
} else {

    $erro = '2';
    $msg  = 'codigo valido!';
}
$xml->addTag('erro',$erro);
$xml->addTag('msg',$msg);
$xml->closeTag('response');

echo $xml;

Classxml.php file:

<?php

/**
 * Description of XmlClass
 *
 * @author Rafael
 */
class Xml {

    private $xml;
    private $tab = 1;
    public function __construct($version="1.0", $encoding="UTF-8") {
        $this->xml .= "<?xml version='$version' encoding='$encoding'?>\n";
    }

    public function openTag($name){
        $this->addTab();
        $this->xml .= "<$name>\n";
        $this->tab++;
    }

    public function closeTag($name){
        $this->tab--;
        $this->addTab();
        $this->xml .= "</$name>\n";        
    }

    public function addTag($name, $value){
        $this->addTab();
        $this->xml .= "<$name>$value</$name>\n";
    }

    private function addTab(){
        for ($i = 1; $i <= $this->tab; $i++){
            $this->xml .= "\t";
        }
    }

    public function __toString() {
        return $this->xml;
    }
}
    
asked by anonymous 08.12.2014 / 01:55

1 answer

1

Your XML file is invalid, meaning it has a syntax error. To check whether the file is valid or not, pass it to an XML validator like this link

    
08.12.2014 / 03:10