第2行第1列错误:文档末尾的其他内容 [英] Error on line 2 at column 1: Extra content at the end of the document
问题描述
当我使用以下代码并在本地解析xml时,它工作正常,但是在服务器上上传相同脚本时,它会显示错误.
When I use the below code and parse the xml locally it works fine but when upload the same script at the server it shows error.
注意:我从查询字符串中检索了$lng
和$lat
,并且在本地运行良好.
Note: I retrieved the $lng
and $lat
from the query string and it works fine locally.
$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;
在服务器上,它将引发此错误.而且文档也为空.....
On the server it throws this error. And the document is also empty.....
此页面包含以下错误:
第2行第1列出现错误:文档末尾的额外内容 下面是直到第一个错误的页面呈现.
This page contains the following errors:
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.
推荐答案
我认为您正在创建一个看起来像这样的文档:
I think you are creating a document that looks like this:
<mycatch>
....
</mycatch>
<mycatch>
....
</mycatch>
这不是有效的XML文档,因为它具有多个根元素.您必须具有一个顶级元素,如
This is not a valid XML document as it has more than one root element. You must have a single top-level element, as in
<mydocument>
<mycatch>
....
</mycatch>
<mycatch>
....
</mycatch>
....
</mydocument>
这篇关于第2行第1列错误:文档末尾的其他内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!