簡體   English   中英

PHP中的XML解析錯誤

[英]XML parsing error in php

當我使用以下代碼並在本地解析xml時,它可以正常工作,但是在服務器上上傳相同腳本時,它會顯示錯誤。 該代碼是

注意:我從查詢字符串中檢索了$lng$lat ,它在本地運行良好。

$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;

在服務器上,我收到此錯誤。 文件也為空.....

此頁面包含以下錯誤:
第2行第1列的錯誤:文檔末尾的額外內容以下是直到第一個錯誤的頁面呈現。

您可能需要為XML文檔定義一個根元素。

此刻你似乎有

<mycatch>
 <catch_id>1</catch_id>
 <catch_details>details</catch_details>
 <image>image</image>
</mycatch>
<mycatch>
 <catch_id>2</catch_id>
 <catch_details>details</catch_details>
 <image>image</image>
</mycatch>
...

但是您沒有諸如以下的根元素:

<catches>
    <mycatch>
     <catch_id>1</catch_id>
     <catch_details>details</catch_details>
     <image>image</image>
    </mycatch>
    <mycatch>
     <catch_id>2</catch_id>
     <catch_details>details</catch_details>
     <image>image</image>
    </mycatch>
</catches>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM