“XML分析错误:文档元素之后的垃圾” [英] "XML Parsing Error: junk after document element"

查看:85
本文介绍了“XML分析错误:文档元素之后的垃圾”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用动态位置显示Google地图,从数据库中检索我正在关注 developer.google.com/maps/articles on phpsqlajax_v3 。我创建了数据库,表格如下所示:


$ b

trnsportpublic表格

transportpublicid int 11 AUTOINCREMENT



transportType varchar 60



costPerKm decimal(7,2)



address varchar 800



teleNo int 10



webLink varchar 300



description varchar 800



lat double(10 ,6)

lng double(10,6)




GenerateXml.php

 <?php 

require( db_connection.php);


函数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;
}

/ /选择标记表中的所有行
$ 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);

//启动XML文件,echo父节点
echo'< transportpublic>';

//迭代($ row = mysql_fetch_assoc($ result)){
//添加到XML DOCUMENT节点
,通过行,为每个
打印XML节点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'/>';
}

//结束XML文件
echo'< / transportpublic>';
?>

当我在浏览器上运行 GenerateXml.php 时,

  XML解析错误:文档元素
之后的垃圾位置:http:// localhost:8080 / testserver / generateXml .php
行号11,列8:
< / html>
< transportpublic>
< marker transportType =BuscostPerKm =1.50address = abcteleNo =112554476webLink =http://www.abc.htmllat =0.000000lng =0.000000/>


< marker transportType =hmmmmcostPerKm =40.00address =abcteleNo =112541254webLink =http://www.abc.htmllat = - 33.005985lng = - 58.501824/>



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






我只知道在根元素之后,我不应该解析任何数据,它会被视为垃圾,但是在我的GenerateXml.php中,我不会在这行之后执行任何操作。

  echo'< / transportpublic>'; 






请帮助我。

解决方案

根节点是< transportpublic> ,但错误消息显示伪造< / html> 紧靠标签。 XML解析器可能认为< html> 是根节点,因此XML的其余部分是文档元素之后的垃圾。错误。

Hey everyone I'm trying to display a Google map with dynamic locations retrieve from database I was following developers.google.com/maps/articles on phpsqlajax_v3.I created the database and the table looks like this

trnsportpublic table

transportpublicid int 11 AUTOINCREMENT

transportType varchar 60

costPerKm decimal(7,2)

address varchar 800

teleNo int 10

webLink varchar 300

description varchar 800

lat double(10,6)

lng double(10,6)


GenerateXml.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>';
    ?>

When I run GenerateXml.php on browser is gives me fillowing

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>
-------^ 


I only got to know that after the root element I shouldn't be parsing any data it'll be taken as junk but in my GenerateXml.php i don't do anything after this line

echo '</transportpublic>';


help me please.

解决方案

The root node is <transportpublic> but the error message shows a bogus </html> close tag right before it. The XML parser probably thinks that <html> is the root node, thus the rest of the XML is the junk after document element mentioned by the error.

这篇关于“XML分析错误:文档元素之后的垃圾”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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