文档末尾的XML Extra内容 [英] XML Extra content at the end of the document

查看:62
本文介绍了文档末尾的XML Extra内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:

error on line 4 at column 1: Extra content at the end of the document

使用以下代码:

    $this->load->database();

    function parseToXML($htmlStr) 
    { 
        $xmlStr=str_replace('<','&lt;',$htmlStr);     
        $xmlStr=str_replace('>','&gt;',$xmlStr); 
        $xmlStr=str_replace('"','&quot;',$xmlStr); 
        $xmlStr=str_replace("'",'&#39;',$xmlStr); 
        $xmlStr=str_replace("&",'&amp;',$xmlStr); 
        return $xmlStr; 
    } 
    $query = $this->db->get('comboTable');
    $query = $query->result_array();
    header("Content-type: text/xml");
    // Start XML file, echo parent node
    echo '<markers>';
    // Iterate through the rows, printing XML nodes for each
    foreach ($query as $row)
    {
      // ADD TO XML DOCUMENT NODE
      echo '<marker ';
      echo 'name="' . parseToXML($row['restaurantName']) . '" ';
      echo 'address="' . parseToXML($row['address']) . '" ';
      echo 'lat="' . $row['lat'] . '" ';
      echo 'lng="' . $row['lng'] . '" ';
      echo '/>';    
    }
    // End XML file
    echo '</markers>';  

推荐答案

如果没有看到文本输出本身,就不可能确定,但​​是我立即注意到了几件事:

Without seeing the text output itself, it would be impossible to know for sure, but there are a couple of things I noticed immediately:

  1. 要调试此消息,请发送标头header("Content-type: text");.
  2. parseToXML试图重新发明轮子,请使用 htmlentities .
  3. (此内容和以下内容应该无关紧要,您应该使用htmlentities)在将其他所有内容替换为实体之后,您要替换&.这意味着您得到的是&amp;lt;而不是&lt;.
  4. str_replace将数组作为参数,最好使用它们.
  1. To debug this, send the header header("Content-type: text");.
  2. parseToXML is an attempt to re-invent the wheel, use htmlentities.
  3. (This and the following should be irrelevant, you should be using htmlentities) You are replacing & after replacing everything else with an entity. This means you're getting, &amp;lt; instead of &lt;.
  4. str_replace takes arrays as parameters, you would be best using them.

这篇关于文档末尾的XML Extra内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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