Reputation: 1982
I am generating xml
file dynamically and getting error when i include newstext. Error: XML Parsing Error: undefined entity
!
By remove newstext xml
generates perfectly. Here is the code i am using.
$sqlNews = "SELECT * FROM news";
$runSqlNews = mysql_query($sqlNews);
while ($rowSqlNews = mysql_fetch_array($runSqlNews))
$arrSqlNews[] = $rowSqlNews;
header('Content-type: text/xml');
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
echo '<xml>';
for($i=0;$i<count($arrSqlNews);$i++)
{
echo "<news>";
echo "<newsId>".$arrSqlNews[$i][id]."</newsId>";
echo "<newsAuthor>".$arrSqlNews[$i][news_author]."</newsAuthor>";
echo "<newsText>".$arrSqlNews[$i][news_text]."</newsText>";
echo "<description>".$arrSqlNews[$i][news_description]."</description>";
echo "<image>".$arrSqlNews[$i][news_image]."</image>";
echo "</news>";
}
echo '</xml>';
Hope my question is clear. Thanks in Advance !!
Upvotes: 2
Views: 523
Reputation: 125610
Try this:
echo "<newsText><![CDATA[".$arrSqlNews[$i][news_text]."]]></newsText>";
It will prevent the browser from parsing tags from that field content.
Upvotes: 1