1

I need to generate sitemap and display in my view.But am getting this error:-

error on line 1 at column 2: StartTag: invalid element name

Controller:-

class Sitemap extends CI_Controller {

public function index()
{
    $this->load->view('sitemap/sitemap.html');
}
}

View:-

<?php header('Content-type: text/xml'); ?>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.domain.com /</loc>
<lastmod>2008-01-01</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://www.domain.com/catalog?item=vacation_hawaii</loc>
<changefreq>weekly</changefreq>
</url>
</urlset> 
VeNaToR
  • 49
  • 2
  • 7
  • 1
    Try removing the .html from your view, unless your view file is called sitemap.html.php – gabe3886 May 01 '15 at 09:22
  • Wrongly interpretated rule. From [docs](http://www.codeigniter.com/userguide3/general/views.html#loading-a-view): "The .php file extension does not need to be specified unless you use something other than .php." so html file is quite allowed to be loaded. – Tpojka May 01 '15 at 10:03

1 Answers1

1

Try like this : Sitemap generation with Codeigniter


contoroller:

Class Sitemap extends CI_Controller {

    function index()
    {

        $data = "";//select urls from DB to Array
        header("Content-Type: text/xml;charset=iso-8859-1");
        $this->load->view("sitemap",$data);
    }
}

view:

<?= '<?xml version="1.0" encoding="UTF-8" ?>' ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc>http://www.domain.com /</loc>
        <lastmod>2008-01-01</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>http://www.domain.com/catalog?item=vacation_hawaii</loc>
        <changefreq>weekly</changefreq>
    </url>
</urlset>

add line to config/routes.php :

$route['seo/sitemap\.xml'] = "seo/sitemap";

=> roev's answer

Community
  • 1
  • 1
Kim
  • 11
  • 3