Opencart sitemap xml error
Opencart sitemap xml error – ‘xmlParseEntityRef: no name’
In Opencart sitemap xml error – xmlParseEntityRef: no name is a common bug which did not eliminate by opencart by it self.
When you need to put your opencart site in to google search index you have add a sitemap xml file to google webmaster tools. For this you can active the default sitmap.xml for the google site indexing. To do this you have to enable Google Sitemap in Extension Feed. For this go to
Extensions -> Feeds -> Google Sitemap
and enable It.
You can see the opencart sitemap xml path like this
http://yoursite.com/index.php?route=extension/feed/google_sitemap
After enable this you can add your site map in google webmaster tools. You can use above url to do that or use
http://yoursite.com/sitemap.xml
If you configured the .htaccess file correctly this sitemap should work.
The problem will be when you are trying to access this sitmap.xml file some times you get an sitemap xml error ‘xmlParseEntityRef: no name’ . This will happen when your xml file contains ‘&’ character instead of ‘&’. To eliminate this issue you can replace google_sitemap.php file with below code.
catalog/controller/extension/feed/google_sitemap.php
<?php class ControllerExtensionFeedGoogleSitemap extends Controller { public function index() { if ($this->config->get('feed_google_sitemap_status')) { $output = '<?xml version="1.0" encoding="UTF-8"?>'; $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">'; $this->load->model('catalog/product'); $this->load->model('tool/image'); $products = $this->model_catalog_product->getProducts(); foreach ($products as $product) { if ($product['image']) { $url = preg_replace('/&(?!#?[a-z0-9]+;)/', '&', $this->url->link('product/product', 'product_id=' . $product['product_id'])); $imgcaption = preg_replace('/&(?!#?[a-z0-9]+;)/', '&', $product['name']); $imgTitle = preg_replace('/&(?!#?[a-z0-9]+;)/', '&', $product['name']); $output .= '<url>'; $output .= ' <loc>' . $url . '</loc>'; $output .= ' <changefreq>weekly</changefreq>'; $output .= ' <lastmod>' . date('Y-m-d\TH:i:sP', strtotime($product['date_modified'])) . '</lastmod>'; $output .= ' <priority>1.0</priority>'; $output .= ' <image:image>'; $output .= ' <image:loc>' . $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height')) . '</image:loc>'; $output .= ' <image:caption>' . $imgcaption . '</image:caption>'; $output .= ' <image:title>' . $imgTitle . '</image:title>'; $output .= ' </image:image>'; $output .= '</url>'; } } $this->load->model('catalog/category'); $output .= $this->getCategories(0); $this->load->model('catalog/manufacturer'); $manufacturers = $this->model_catalog_manufacturer->getManufacturers(); foreach ($manufacturers as $manufacturer) { $output .= '<url>'; $output .= ' <loc>' . $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $manufacturer['manufacturer_id']) . '</loc>'; $output .= ' <changefreq>weekly</changefreq>'; $output .= ' <priority>0.7</priority>'; $output .= '</url>'; $products = $this->model_catalog_product->getProducts(array('filter_manufacturer_id' => $manufacturer['manufacturer_id'])); foreach ($products as $product) { $output .= '<url>'; $output .= ' <loc>' . $this->url->link('product/product', 'manufacturer_id=' . $manufacturer['manufacturer_id'] . '&product_id=' . $product['product_id']) . '</loc>'; $output .= ' <changefreq>weekly</changefreq>'; $output .= ' <priority>1.0</priority>'; $output .= '</url>'; } } $this->load->model('catalog/information'); $informations = $this->model_catalog_information->getInformations(); foreach ($informations as $information) { $output .= '<url>'; $output .= ' <loc>' . $this->url->link('information/information', 'information_id=' . $information['information_id']) . '</loc>'; $output .= ' <changefreq>weekly</changefreq>'; $output .= ' <priority>0.5</priority>'; $output .= '</url>'; } $output .= '</urlset>'; $this->response->addHeader('Content-Type: application/xml'); $this->response->setOutput($output); } } protected function getCategories($parent_id, $current_path = '') { $output = ''; $results = $this->model_catalog_category->getCategories($parent_id); foreach ($results as $result) { if (!$current_path) { $new_path = $result['category_id']; } else { $new_path = $current_path . '_' . $result['category_id']; } $url = preg_replace('/&(?!#?[a-z0-9]+;)/', '&', $this->url->link('product/category', 'path=' . $new_path)); $output .= '<url>'; $output .= ' <loc>' . $url . '</loc>'; $output .= ' <changefreq>weekly</changefreq>'; $output .= ' <priority>0.7</priority>'; $output .= '</url>'; $products = $this->model_catalog_product->getProducts(array('filter_category_id' => $result['category_id'])); foreach ($products as $product) { $purl = preg_replace('/&(?!#?[a-z0-9]+;)/', '&', $this->url->link('product/product', 'path=' . $new_path . '&product_id=' . $product['product_id'])); $output .= '<url>'; $output .= ' <loc>' . $purl . '</loc>'; $output .= ' <changefreq>weekly</changefreq>'; $output .= ' <priority>1.0</priority>'; $output .= '</url>'; } $output .= $this->getCategories($result['category_id'], $new_path); } return $output; } }
Finally go to the extension->modification and refresh the cache and try again.You can see that sitemap xml error is not appearing and your sitemap path should work fine. And then add it the google webmaster tools.