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)
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
Related
I have error:
This page contains the following errors:
error on line 4 at column 6: XML declaration allowed only at the start of
the document
Below is a rendering of the page up to the first error.
<?php include 'config.php';
header("Content-Type: text/xml");
echo '<?xml version="1.0" encoding= "utf-8"?>';
echo '<urlset
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">';
echo '<url>
<loc>http://cebhe.info/</loc>
<changefreq>always</changefreq>
</url>';
$get_menus_sql = $db->prepare("SELECT id,ad FROM kateqoriyalar");
$get_menus->execute();
foreach($get_menus_sql as $get_menus){
$menu_name = $get_menus['id'];
$menu_slug = $get_menus['ad'];
if($pagename == $menu_slug)
{$menuselected = 'select';}else{$menuselected = '';}
echo'
<url>
<loc>http://cebhe.info/kat.php?'.$menu_name.'</loc>
<changefreq>always</changefreq>
</url>'; }
$sitemap=$db->prepare("SELECT * FROM yazilar ORDER BY id DESC LIMIT 10");
$sitemap->execute();
foreach($sitemap as $sm){
echo'
<url>
<loc>http://cebhe.info/'.seolink(strip_tags($sm['basliq'])).'-'.$sm['id'].'</loc>
<changefreq>always</changefreq>
</url>
';}
echo '</urlset>';?>
I'm using a script to display a page in XML, but I need it to display at start but whenever I try, it breaks the code.
Heres the code I tried:
<?php
header('Content-Type: application/xml');
$output = "
<?xml version='1.0' encoding='utf-8' ?>
";
print ($output);
?>
but its not working, any help ?
use echo , Basic Simple XML
<?php
header('Content-Type: application/xml');
$output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo $output;
?>
yes, use echo, but you don't need additional variable and you can use single quote string without backslash...
<?php
header('Content-Type: application/xml');
echo '<?xml version="1.0" encoding="UTF-8"?' . ">\n"; //connate strings to protect end of php formatting in simple editors, and use new line tag
?>
I wish to create some custom namespaces in my rss feed.
The problem is that I have the rss feed working, but the custom namespace data does not show up. I have got it to this far but if anyone could assist in showing how to get this to work properly ( if at all) it would be greatly appreciated.
below is the code i am using to achieve this to this point.
the reason for custom naming is that I am unable to attach the data to anything else that has been already approved.
<?
//Configure the Basic information
$chan_title = "sponsor";
$chan_desc = "some sponsor data.";
$chan_link = "http://pandafc.elementfx.com/panda_app_page.php";
//$image_url = "logo.gif";
//connect to the Database
include 'connect.php';
$query = "SELECT sp_ID, sp_name, sp_about, sp_website FROM sponsors ORDER BY sp_ID DESC LIMIT 25";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) < 1) {
die("No records");
}
//Build the XML data
$items = '';
while ($row = mysql_fetch_assoc($result)) {
$item_id = $row["sp_ID"];
$item_title = $row["sp_name"];
$item_link = $row["sp_about"];
$item_desc = $row["sp_website"];
$items .= <<<ITEM
<item>
<title>$item_id</title>
<sponsor:sponsor>$item_title</sponsor:sponsor>
<sponsor:about>$item_link</sponsor:about>
<sponsor:Website>$item_desc</sponsor:Website>
</item>
ITEM;
}
$content = <<<CONTENT
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:sponsor="http://pandafc.elementfx.com/nssponsor.xhtml" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>$chan_title</title>
<link>$chan_link</link>
<description>$chan_desc</description>
$items
<atom:link href="http://pandafc.elementfx.com/rssfeed1.php" />
</channel>
</rss>
CONTENT;
//print results on screen
header("Content-type: application/rss+xml");
print $content;
?>
hopefully this can be achieved and others may also find this useful
I need to make TOP 10 players table in flash. When I click button "TOP 10" it must get data from database and print list on the game screen.
What I want to make here is vision:
I have dynamically created XML from PHP and data must be sent to Action Script 3.
Here is top.php file
<?php
$time = $_POST['time'];
session_start();
$name = $_SESSION['vardas'];
$time = strtotime($time);
$times = date('s:H:i', $time);
$_SESSION['test'] = $times;
$_SESSION['test1'] = $username;
$mysqli = new mysqli("localhost","my_db","pass","my_db");
$query = "SELECT userName,time FROM eurokos ORDER by time ASC LIMIT 10";
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
// printf(" ", $mysqli->character_set_name());
}
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<results>';
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
echo '<user name="'.$row["userName"].'" time="'.$row["time"].'" />';
}
$result->free();
}
echo '</results>';
$mysqli->close();
?>
XML looks like:
<?xml version="1.0" encoding="UTF-8"?>
<results>
<user name="someone" time="xxx" />
<user name="someone" time="xxx" />
[...]
</results>
And here is my Action Script code:
var myXml:XML;
function uploadTops():void
{
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("top.php"));
myLoader.addEventListener(Event.COMPLETE, processXML);
}
function processXML(e:Event):void {
myXml = new XML(e.target.data);
trace(myXml);
}
function myButton(e:MouseEvent):void
{
uploadTops();
// _message = myXml.user.*; //these lines are wrong, I donn't know how to print answer
// message_txt.text = _message;
}
I got error:
Error #1090: XML parser failure: element is malformed. when trying to trace
at MemoryGame/processXML()[C:\Users\Petras\Downloads\geraseaa\geraseaa\gerase\MemoryGame.as:570]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Thank you for answers.
Try to open your XML file with a browser and then see its source , this way you will know what exactly wrong with your XML file.
It's possible that if you will add in your php file this line :
header('Content-Type: text/xml');
before this line:
echo '<?xml version="1.0" encoding="UTF-8"?>';
it will help
I got the following error,
An invalid character was found in text content. Error processing resource
when I dynamically created xml file using php.The encoding I used was utf-8.I changed it to ISO-8859-1.The error resolved.But the issue is I am having tamil,hindi content So it is displayed as
à®à®à¯à®°à®¾-à®à¯à®à¯à®à¯-
header('Content-Type: application/xml'); echo '<?xml version="1.0" encoding="UTF-8"?>'."\n"; ?> <urlset xmlns="http://www.google.com/schemas/sitemap/0.84"> <?php $sql = "SELECT * FROM table "; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { ?> <url> <loc>http://example.com/<?php echo $row[2]; ?></loc> <lastmod><?php echo str_replace(' ', 'T', $row['dat']).substr(date("O"), 0, -2).':00'; ?></lastmod> </url> <?php } ?></urlset>
How to solve this?
Regards
Rekha
http://hiox.org
adding code from comment below:
<?
header('Content-Type: application/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
<?php
$sql = "SELECT * FROM table ";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
?>
<url>
<loc>http://example.com/<?php echo $row[2]; ?></loc>
<lastmod><?php echo str_replace(' ', 'T', $row['dat']).substr(date("O"), 0, -2).':00'; ?></lastmod>
</url>
<?php } ?>
</urlset>
ISO-8859-1 does not have the coverage over hindi and tamil alphabets