3

大家好,我正在尝试显示带有从数据库中检索的动态位置的Google地图

trnsport公共表

transportpublicid int 11 自动增量

传输类型 varchar 60

costPerKm 小数(7,2)

地址 varchar 800

电话号码 int 10

网络链接 varchar 300

说明 varchar 800

纬度双 (10,6)

液化天然气双(10,6)


生成XML.php

 <?php

          require("db_connection.php");


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

          // Select all the rows in the markers table
          $query = "SELECT transportType,costPerKm,address,teleNo,webLink,lat,lng FROM transportpublic";

          $result = mysql_query($query);
          if (!$result) 
          {
            die('Invalid query: ' . mysql_error());
          }

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

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

          // Iterate through the rows, printing XML nodes for each
          while ($row = mysql_fetch_assoc($result)){
            // ADD TO XML DOCUMENT NODE
            echo '<marker ';
            echo 'transportType="' . parseToXML($row['transportType']) . '" ';
            echo 'costPerKm="' . $row['costPerKm'] . '" ';
            echo 'address="' . parseToXML($row['address']) . '" ';
            echo 'teleNo="' . $row['teleNo'] . '" ';
            echo 'webLink="' . parseToXML($row['webLink']) . '" ';
            echo 'lat="' . $row['lat'] . '" ';
            echo 'lng="' . $row['lng'] . '" ';
            echo '/>';
          }

          // End XML file
          echo '</transportpublic>';
    ?>

当我在浏览器上运行GenerateXml.php时,我会感到困惑

XML Parsing Error: junk after document element
Location: http://localhost:8080/testserver/generateXml.php
Line Number 11, Column 8:
</html>
<transportpublic>
<marker transportType="Bus" costPerKm="1.50" address="abc" teleNo="112554476" webLink="http://www.abc.html" lat="0.000000" lng="0.000000" />

<marker transportType="Train" costPerKm="12.00" address="abc" teleNo="118745963" webLink="http://www.abc.html" lat="0.000000" lng="0.000000" />

<marker transportType="hmmmm" costPerKm="40.00" address="abc" teleNo="112541254" webLink="http://www.abc.html" lat="-33.005985" lng="-58.501824" />

<marker transportType="test" costPerKm="2.00" address="abc" teleNo="112541258" webLink="http://www.abc.html" lat="39.785999" lng="-75.041976" />

<marker transportType="test2" costPerKm="2.00" address="abc" teleNo="112541254" webLink="http://www.abc.html" lat="6.901698" lng="79.853854" />

</transportpublic>
-------^ 

我只知道在根元素之后我不应该解析任何数据,它将被视为垃圾,但在我的 GenerateXml.php 中,我在此行之后不做任何事情

echo '</transportpublic>';

请帮帮我。

4

1 回答 1

5

根节点是<transportpublic>,但错误消息</html>在它之前显示了一个虚假的关闭标记。XML 解析器可能认为这<html>是根节点,因此 XML 的其余部分是错误提到的文档元素之后的垃圾。

于 2013-04-02T12:00:56.370 回答