当使用 sitemap()
view helper 输出 Zend Navigation 时,出现以下错误:
Sitemap is invalid according to XML Schema at "http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
验证开启:
$this->navigation()->setUseSchemaValidation(true)->setFormatOutput(true);
- 如何使用 Zend Framework 呈现有效的 xml 站点地图?
我的站点地图是这样的:
<?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>
最佳答案
先决条件:
DomDocument::schemaValidate($path) 在 allow_url_fopen 之前不会工作已启用
关于站点地图:
来自 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>
要将这些 header 添加到您的 XML,您首先需要通过 $domDoc = $this->sitemap()->getDomSitemap()
检索 DomDocument
而不是添加额外的 header ,最后 echo $domDoc->saveXml()
在你看来我做这么多似乎不太好,也许一个额外的 ViewHelper 子类 Zend_View_Helper_Navigation_Sitemap 可能适合你。
不幸的是,我还没有使用过 DomDocument,所以我无法帮助设置命名空间属性,可能是 this post会帮助你的。
关于xml - Zend Framework 站点地图验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4631415/