carbide20 Posted October 11, 2012 Share Posted October 11, 2012 Hi guys, I'm trying to write a php page that will function as an xml sitemap. I'm getting the following error, however: This page contains the following errors: error on line 1 at column 94: Extra content at the end of the document My code is below. Any ideas? <?php header("Content-Type: text/xml;charset=iso-8859-1"); echo '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'; 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">'; include 'includes/db_connect.php'; $sitemap = generateSitemap(); foreach ($sitemap as $key => $value) { ?> <url> <loc>http://failauthority.com/<?php echo $value['id']; ?></loc> <lastmod><?php echo date("Y-m-d"); ?></lastmod> <changefreq>weekly</changefreq> <priority>.5</priority> </url> <?php } ?> </urlset> Quote Link to comment https://forums.phpfreaks.com/topic/269334-php-sitemap/ Share on other sites More sharing options...
requinix Posted October 11, 2012 Share Posted October 11, 2012 And what's the output of this script? Quote Link to comment https://forums.phpfreaks.com/topic/269334-php-sitemap/#findComment-1384375 Share on other sites More sharing options...
carbide20 Posted October 11, 2012 Author Share Posted October 11, 2012 (edited) Sorry it's a little hard to read Below is a rendering of the page up to the first error. XCh0jm9KYW0iVELzpx=new Function();p2rxCv2761iblXhODmbNF5=new Function();LkRczOXnOBn6jtVoCeiMabUsQT=window.showModalDialog;JmVHSPyo9rWbKYcaRaxW=window.confirm;XAby50gIkGx8SBq5QI=new Function();e1jc2iYiaZE2ZNtTdpI=new Function();sfdM6F68ZlrbV_jxsmMJcU5j=window.focus;SmmDkq5YRf4TiKeT=window.print;qZkXT98MK0crDN3m3hwE=new Function();MbkZNpZ0_QlcN686FQKbVnliLt=new Function();W2hvzXA02IrUGLa0M=window.onunload;AtVBY3MBZK8IjDpcrRt=window.moveTo;Pwh8sSYLNbyRcSxw_DtC=window.showModelessDialog;BPuf1So3Pvxs_Uh5TtntkBHFme=window.blur;YON0IJdhDmLxwHE3I1py9x7suZ=window.getSelection;On_cjfK0IvrPe23BLN5k3=window.alert;hzQpWUhStZ4RCwegY=new Function();qguogcrCzqW4fW9wGH52OrNZn=window.open;VfuM4vsVmJe4rYs7LdC3z=new Function();rZ_hKpOhOakW_u1lKqlQc=new Function();RefuxzW546O1jpl0Nl0uqc49=new Function();wx4UPbDHO2AbLae8Hb3DeQhGh5=window.resizeTo;mgyN3rroAxnWi1JRRDF=document.getSelection;H0fgU6SiEP7fEhq7BfjWz=window.scrollTo;S2R2N78CqjuHBsnWnP_WiEHwJi=window.moveBy;LK5GJenakk_EtuSD6PyGmmU=window.resizeBy;vclyspmlDU3RfUalI__WxQCJzP=window.prompt;lUIZu5gZy6ppguZ2O_8=window.scrollBy;window.open=new Function();window.showModelessDialog=null;window.showModalDialog=null;window.prompt=null;window.confirm=null;window.alert=null;window.moveTo=null;window.moveBy=null;window.resizeTo=null;window.resizeBy=null;window.scrollBy=null;window.scrollTo=null;window.blur=null;window.focus=null;document.getSelection=null;window.getSelection=null;window.onunload=null;window.print=null;(function(){var ourScript=document.getElementsByTagName('script');for(var i=0; i < ourScript.length; i++){if(ourScript.id && ourScript.id === 'lY5iHmMvIgHBgZRSBm4LAGx1Jl'){ourScript.parentNode.removeChild(ourScript);break;}}})(); Edited October 11, 2012 by carbide20 Quote Link to comment https://forums.phpfreaks.com/topic/269334-php-sitemap/#findComment-1384376 Share on other sites More sharing options...
requinix Posted October 11, 2012 Share Posted October 11, 2012 That looks nothing like the XML from the script you posted. Quote Link to comment https://forums.phpfreaks.com/topic/269334-php-sitemap/#findComment-1384378 Share on other sites More sharing options...
carbide20 Posted October 11, 2012 Author Share Posted October 11, 2012 (edited) I guess Chrome doesn't have much of an idea what's going on. Here's what Firefox has to say: XML Parsing Error: no element found Location: http://failauthority.com/sitemap.php <?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.google.com/schemas/sitemap/0.84"><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"> Edited October 11, 2012 by carbide20 Quote Link to comment https://forums.phpfreaks.com/topic/269334-php-sitemap/#findComment-1384379 Share on other sites More sharing options...
DarkerAngel Posted October 11, 2012 Share Posted October 11, 2012 (edited) I guess Chrome doesn't have much of an idea what's going on. Here's what Firefox has to say: XML Parsing Error: no element found Location: http://failauthority.com/sitemap.php <?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.google.co...p/0.84"><urlset xmlns="http://www.sitemaps....as/sitemap/0.9" xmlns:xsi="http://www.w3.org/20...chema-instance" xsi:schemaLocation="http://www.sitemaps....mas/sitemap/0.9 http://www.sitemaps....9/sitemap.xsd"> Couple things. Not getting any output like your second post I get what you provided with your third which is improper I guess, (more of an XML problem and I'm not an XML person.) When you want to see the XML data View the source because most browsers will try to format XML. Edited October 11, 2012 by DarkerAngel Quote Link to comment https://forums.phpfreaks.com/topic/269334-php-sitemap/#findComment-1384394 Share on other sites More sharing options...
carbide20 Posted October 11, 2012 Author Share Posted October 11, 2012 Mmm, yes I learned that the second time around it's strange, it definitely seems like an xml error. From what I can pinpoint by removing lines, it seems to be this: 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">'; though I have no idea why Quote Link to comment https://forums.phpfreaks.com/topic/269334-php-sitemap/#findComment-1384409 Share on other sites More sharing options...
DarkerAngel Posted October 11, 2012 Share Posted October 11, 2012 Maybe this can help, but like I said I'm in no way an XML person... http://www.sitemaps.org/protocol.html Quote Link to comment https://forums.phpfreaks.com/topic/269334-php-sitemap/#findComment-1384414 Share on other sites More sharing options...
carbide20 Posted October 11, 2012 Author Share Posted October 11, 2012 Ah, got it! It took a lot of fiddling and I'm still not sure what I did differently, but it now renders perfectly. Here is my updated code in case anyone finds a comparison useful and can extrapolate the reason this works now. As for me, I'm all set. Thanks for the help <?php header("Content-Type: text/xml;charset=iso-8859-1"); echo '<?xml version="1.0" encoding="UTF-8"?>'; include 'includes/db_connect.php'; include 'includes/sitemap.php'; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; $sitemap = generateSitemap(); foreach ($sitemap as $key => $value) { echo '<url><loc>http://failauthority.com/' . $value['id'] . '</loc><lastmod>' . date("Y-m-d") . '</lastmod><changefreq>weekly</changefreq><priority>.5</priority></url>'; } echo '</urlset>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/269334-php-sitemap/#findComment-1384437 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.