2011-01-08 132 views
4

当使用Zend导航sitemap()视图助手输出,我得到以下错误:Zend框架的Sitemap验证

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

验证已开启:

$this->navigation()->setUseSchemaValidation(true)->setFormatOutput(true); 
  • 如何使有效的XML使用Zend框架的网站地图?

我的网站地图看起来是这样的:

<?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> 

回答

3

前提
的DomDocument :: schemaValidate($ PATH),直到allow_url_fopen启用

关于Sitemap将无法​​正常工作:
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> 

那些头添加到您的XML,你首先需要通过$domDoc = $this->sitemap()->getDomSitemap() 检索DOM文档不是增加额外的头终于echo $domDoc->saveXml()

似乎并不高兴我做了这么多你的看法,也许一个额外的ViewHelper子类Zend_View_Helper_Navigation_Sitemap可能适合你。

不幸的是,我从来没有使用DomDocument,所以我不能帮助设置名称空间属性,也许this post会帮助你。

+0

谢谢。我已经添加了这些标题,但我仍然收到相同的错误。问题是`setUseSchemaValidation()`需要`allow_url_fopen`指令被启用,这在我的生产服务器上是默认关闭的。 – takeshin 2011-01-08 09:43:41