I have build a simple site map script, i am not able to get URL output in URL field.
My PHP Script.
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">
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
';
require_once('_ls-global/php/sr-connect.php');
$db = mysql_select_db($database,$connection) or trigger_error("SQL", E_USER_ERROR);
$sqlquery = mysql_query("SELECT * FROM $tablename ORDER by id")or die (mysql_error());
while ($list = mysql_fetch_assoc($sqlquery)){
$pflink=$list['pflink'];
$pagelink=$list['pagelink'];
$site="http://mysite.com";
$url='$site/$pflink/$pagelink';
$changefreq="weekly";
$priority="1.0";
echo '<url>
<loc>'.$url.'</loc>
<changefreq>'.$changefreq.'</changefreq>
<priority>'.$priority.'</priority>
</url>';
}
echo '</urlset>';
The Output of this script is this.
<url>
<loc>$site/$pflink/$pagelink</loc>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
If i change $url='$site/$pflink/$pagelink'; to $url="$site/$pflink/$pagelink";
then i get only one value and error “XML Parsing Error: not well-formed”.
Please see and suggest any modification to make it work.
Thanks
I guess you are having characters in the vars which are messing up the XML.
For example
&,ä,<,>… You need to encode the content correctly.Try wrapping the output:
At first change
$urlto$url = $site .'/'. $pflink .'/'. $pagelink;and then update the output of the XML to:Explanation to
CDATAavailable at http://en.wikipedia.org/wiki/CDATA