开发者

XML/PHP : Content is not allowed in prolog

i have this message error and i don't know where does the problem comes from:

<?php include "DBconnection.class.php";

$sql = DBConnection::getInstance(); 

$requete = "my resquest (which is working)";

$sql->query($requete);  

 $xml = '<?xml version="1.0" encoding="UTF-8"?>';
 $xml .='<GamerCertified>';


            while($row = $sql->fetchArray()){

            $moyenne_services =  ($row['services'] + $row['serviceCli']  + $row['interface'] )/3;
            $moyenne_services = round( $moyenne_services,1);

            $moyenne_ge =  ($row['services'] + $row['serviceCli']  + $row['interface'] + $row['qualite'] + $row['rapport'] ) /5;
            $moyenne_ge = round( $moyenne_ge,1);

             $xml .= '<GSP>';

             $xml .= '<nom>'.$row["nom"].'</nom>';

             $xml .= '<votes>'.$row["nb_votes"].'</votes>';

             $xml .= '<services>'.$moyenne_services.'</services>';

             $xml .= '<qualite>'.$row["qualite"].'</qualite>';

             $xml .= '<prix>'.$row["rapport"].'</prix>';

             $xml .= '<transparence>'.$row["transparence"].'</transparence>';

              $xml .= '<moyenneGenerale>'.$moyenne_ge.'</moyenneGenerale>'; 

 开发者_如何学Go            $xml .= '<serveursDedies>'.$row["offreDedie"].'</serveursDedies>';

             $xml .= '</GSP>';
        }


 $xml .= '</GamerCertified>';
 echo $xml;

Thanks

(PS: FF /chrome echoes that without tag : bc2x56.99.89.8081ckras1710.09.0080crazy-fun-game11010.010.00100crystal-serv349.79.69.509.60dedicore69.49.38.609.21)


XML Preamble should be on its own line. Your tag <GamerCertified> is not recognized as a tag.

Just add start the tag on a new line and the error will go away.

EDIT: Please try this,

 $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
 $xml .='<GamerCertified>';


I think the problem is somewhere else. Try using the following code:

$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

instead of:

$xml = '<?xml version="1.0" encoding="UTF-8"?>';

This is because you are storing the whole XML text in a PHP variable, which sometimes go awry.

Also please take care that you don't print any whitespace character before the XML start tag (<?xml...). And just use one carriage return (like the "enter" key of your keyboard) after the XML definition end tag (...encoding="UTF-8"?>), so as to start your XML's first start tag (<GameCertified>).

Hope it helps.


Well, first off, remove the spaces before the opening <?php tag. Second, is that the only file in the script? Are there any non-whitespace characters occurring after the </GamerCertified> tag? If so, that's most likely the issue.


I had the same problem.

finaly found that it was the include file (in your case the "DBconnection.class.php" file)

the include files was saved on utf-8. The file editor have the option to save in "utf-8" or "utf-8 without BOM" changing to the second option for my include files worked out for me... and removed the content before the xml tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜