具有PHP"echo"的XML出现错误“文档末尾的额外内容"; [英] XML with PHP "echo" getting error "Extra content at the end of the document"

查看:132
本文介绍了具有PHP"echo"的XML出现错误“文档末尾的额外内容";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个我认为非常具体的错误.

I'm getting an error that I believe to be very specific.

此PHP存储在我的域中.它使用mysql数据库访问服务器,并使用其表信息生成带有标记的XML,此标记随后将在Google Map中使用.

This PHP is stored in my domain. It access a server with a mysql database and uses it's table information to generate an XML with markers, that will afterwards be used in Google Map.

实际上,它正在工作,因为它正在检索标记,但是该错误不会消失,而且我也不知道是什么原因造成的.我是所有php和android编程的新手.如果有人可以通过简单的解释为我澄清这一点,我将非常感激.

Actually it is working because it's retrieving the markers, but this error doesn't go away, and I don't know what's causing it. I'm very new to all the php and android programming. If someone could clarify this for me with easy explanation, I would be greatful.

错误是:

This page contains the following errors:

error on line 3 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.

然后呈现我的预期结果.我想解决并理解为什么会发生这种情况.

And then it renders my expected result. I would like to solve and understand why this happens.

您去了我的PHP代码.我从本教程中学到了( https://developers.google.com/maps/articles/phpsqlajax_v3):

There you go my php code. I got from the tutorial (https://developers.google.com/maps/articles/phpsqlajax_v3):

<?php
require("db_config.php");

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&#39;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

// Opens a connection to a MySQL server

$connection=mysql_connect ($mysql_host, $mysql_user, $mysql_password);
if (!$connection) {  die('Not connected : ' . mysql_error());}

// Set the active MySQL database

$db_selected = mysql_select_db($mysql_database, $connection);
if (!$db_selected) {
    die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table
$query = "SELECT * FROM Estac WHERE 1";
$result = mysql_query($query);
if (!$result) {
        die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker>';
  echo 'Name="' . parseToXML($row['Name']) . '" ';
  echo 'Address="' . parseToXML($row['Address']) . '" ';
  echo 'Tel="' . parseToXML($row['Tel']) . '" ';
  echo 'Lat="' . $row['Lat'] . '" ';
  echo 'Lng="' . $row['Lng'] . '" ';
  echo 'Price="' . $row['Price'] . '" ';
  echo '</marker>';
}

// End XML file
echo '</markers>';

?>

非常感谢!

推荐答案

只需右键单击您的输出错误网页并查看源代码,您将在PHP文件中看到正确的错误消息和行号.您将在几秒钟内解决该错误.

Just Right click your output error webpage and VIEW SOURCE CODE you will see the correct error message and line number from your PHP file. You will solve that error in few seconds.

这篇关于具有PHP"echo"的XML出现错误“文档末尾的额外内容";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆