4
votes

When outputting Zend Navigation using sitemap() view helper, I get the following error:

Sitemap is invalid according to XML Schema at "http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"

The validation is turned on:

$this->navigation()->setUseSchemaValidation(true)->setFormatOutput(true);
  • How to render valid xml sitemap using Zend Framework?

My sitemap looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>http://example.com/index/index/slug/news</loc>
  </url>
  <url>
    <loc>http://example.com/strona/test-page</loc>
  </url>
  <url>

    <loc>http://example.com/strona/test-submenu</loc>
  </url>
  <url>
    <loc>http://example.com/strona/subpage-submenu</loc>
  </url>
  <url>
    <loc>http://example.com/strona/test-submenu-1</loc>

  </url>
  <url>
    <loc>http://example.com/feed/list</loc>
  </url>
  <url>
    <loc>http://example.com/default/sitemap</loc>
  </url>
</urlset>
1

1 Answers

3
votes

Precondition:
DomDocument::schemaValidate($path) won't work until allow_url_fopen is enabled

About Sitemaps:
From http://www.sitemaps.org/protocol.php#validating

In order to validate your Sitemap or Sitemap index file against a schema, the XML file will need additional headers as shown below.

<?xml version='1.0' encoding='UTF-8'?>
<urlset 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"
        xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      ...
   </url>
</urlset>

to add those headers to your XML you first need to retrieve the DomDocument via $domDoc = $this->sitemap()->getDomSitemap() than add the additional headers and finally echo $domDoc->saveXml()

doesnt seem nice to me to do so much in your view, maybe an additional ViewHelper subclassing Zend_View_Helper_Navigation_Sitemap may be appropriate for you.

Unfortunately I have never worked with DomDocument yet, so I can't help with setting the namespace attributes, maybe this post will help you for that.