首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何处理 Error on line 2 at column 1: Extra content at the end of the document?

如何处理 Error on line 2 at column 1: Extra content at the end of the document?

提问于 2018-01-29 00:00:09
回答 2关注 0查看 1.4K

当我使用下面的代码并在本地解析XML时,它可以正常工作,但是当在服务器上上传相同的脚本时,它会显示错误。

注意:我检索了$lng$lat从查询字符串中,它在本地工作得很好。

代码语言:txt
复制
$lng=$_GET['lng'];
$lat=$_GET['lat'];
$conn=new LoginSystem();
$conn->connect();
$dom = new DOMDocument("1.0");

$query="select catch_id,catch_details,image from mycatch where longitude='$lng' AND latitude='$lat'";
$result = mysql_query($query);

if (!$result) {
  die("Invalid query: " . mysql_error());
}

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

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  $node = $dom->createElement("mycatch");
  $node = $dom->appendChild($node);
foreach ($row as $fieldname => $fieldvalue) {
      $child = $dom->createElement($fieldname);
    $child = $node->appendChild($child);
    $value = $dom->createTextNode($fieldvalue);
    $value = $child->appendChild($value);
  }
}

$conn->disconnect();
$xml_string = $dom->saveXML();
echo $xml_string;

它在服务器上抛出此错误。文件也是空的...

此页面包含以下错误: error on line 2 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error.

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档