0

Hello stackoverflow community,

this code display the url for my sitemap, the connection work correctly and display the url list (not very well) the error code i can see in the header

This page contains the following errors: error on line 2 at column 18210: xmlParseEntityRef: no name Below is a rendering of the page up to the first error.

<?php 
header('Content-type: application/xml; charset=utf-8') ?>
<?php 
echo '<?xml version="1.0" encoding="UTF-8"?>' ?>

<?php

define('DBHOST','localhost');
define('DBUSER','user');
define('DBNAME','database');
define('DBPWD','password');
$connect = new MySQLi(DBHOST,DBUSER,DBPWD,DBNAME)or die(mysqli_error());

echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
echo '<url>';

$query = $connect->query("select * from rss");
while($row=$query->fetch_array(MYSQL_ASSOC))
{

echo '<loc>'.$row['link'].'</loc>';

}
echo '</url>';
echo '</urlset>';
?>

the code above output this (does this look correct ?)

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>http://www.exemple.com/d/brown</loc>
<loc>http://www.exemple.com/d/blue</loc>
<loc>http://www.exemple.com/d/red/</loc> 
<loc>http://www.exemple.com/d/yellow</loc>
//more lines
</url></urlset>

i would like to know what i did wrong on this code thanks you very much

(French Pierre)

1 Answer 1

0

i fixed the problem ,the error came from one field in the rss table contain a bad character ..., but i have added missing xml parameters

lastmod, changefreq, priority

<?php 
define('DBHOST','localhost');
define('DBUSER','user');
define('DBNAME','rss');
define('DBPWD','password');
$connect = new MySQLi(DBHOST,DBUSER,DBPWD,DBNAME)or die(mysqli_error());

header("Content-Type: text/xml;charset=iso-8859-1");  
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">";

    {

$query = $connect->query("select * from rss");
while($row=$query->fetch_array(MYSQL_ASSOC)) { 
  $url = $row["link"];
  $time = $row["when"];
  $lastmod = $time; 
  $datetime = new DateTime($lastmod);
  $timeresult = $datetime->format('Y-m-d\TH:i:sP');

  echo "<url>
      <loc>$url</loc>
      <lastmod>$timeresult</lastmod>
      <changefreq>hourly</changefreq>
      <priority>0.8</priority>
  </url>
";}}
?>
</urlset>

like this the output does not give error anymore it does pass google validation

thanks you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.