0

I am trying to develop my own XML RSS feed based on PHP output from MySQL queries. However I keep getting "entity X not defined" error messages for all the ASCII characters in my DB content fields, even though I have set everything to UTF8 encoding and charset (database connection, xml version, utf8_encode), but nothing removes the error:

<?php
$connection = mysqli_connect( .... )
$connection->set_charset("utf8");
header("Content-type: text/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="utf-8"?>';
echo '<rss version="2.0">';
$query = mysqli_query($connection,"SELECT * FROM news ORDER BY pubdate DESC LIMIT 10");
while($row = mysqli_fetch_assoc($query)){
$title = utf8_encode($row['title']);
$content = utf8_encode($row['content']);
echo '<item><title>'.$title.'</title>';
echo '<description>'.$content.'</description></item>';
} // end while
echo '</channel>';
echo '</rss>';
?>

What am I missing?

Thanks a lot!

2
  • Please include the generated XML code (or a sufficiently long extract thereof) in the question. Commented Jun 12, 2014 at 9:11
  • The problem you have is that you create the XML by hand instead of using a library that has been created for creating XML, like in your case for example SimpleXML or DOMDocument. Those libraries take care of the proper XML encoding of UTF-8 encoded strings you get from your database. Commented Jun 12, 2014 at 19:30

2 Answers 2

2

I also faced the same issue and fixed using below link

I think you are looking for this

http://help.simplytestable.com/errors/html-validation/general-entity-x-not-defined-and-no-default-entity/

Sign up to request clarification or add additional context in comments.

1 Comment

I'm the author of the above-linked help article. Good to see it coming in useful!
1

You will have to escape the $title and $content variables. Check htmlspecialchars().

For a better solution, use DOM to create the the XML. This will make sure that you create a valid XML.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.