文档末尾的XML Extra内容 [英] XML Extra content at the end of the document
本文介绍了文档末尾的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('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$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:
- 要调试此消息,请发送标头
header("Content-type: text");
. - parseToXML试图重新发明轮子,请使用
htmlentities
. - (此内容和以下内容应该无关紧要,您应该使用htmlentities)在将其他所有内容替换为实体之后,您要替换
&
.这意味着您得到的是&lt;
而不是<
. -
str_replace
将数组作为参数,最好使用它们.
- To debug this, send the header
header("Content-type: text");
. - parseToXML is an attempt to re-invent the wheel, use
htmlentities
. - (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,&lt;
instead of<
. str_replace
takes arrays as parameters, you would be best using them.
这篇关于文档末尾的XML Extra内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文