【问题标题】:xml sitemap not displaying in xml formatxml 站点地图未以 xml 格式显示
【发布时间】:2013-10-12 13:40:24
【问题描述】:

我想以正确的 xml 格式显示我的站点地图,但它显示在一行中:

http://www.example.com/home 1.00 http://www.example.com/about 0.50 http://www.example.com/login 0.20 http://www. etc

不是:

<?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
      <url>
        <loc>http://www.example.com/home</loc>
        <priority>1.00</priority>
      </url>
      <url>
        <loc>http://www.example.com/about</loc>
        <priority>0.50</priority>
      </url>
      etc.

我在 SitemapController 中的代码:

<?php
    class SitemapController extends Zend_Controller_Action
    {
            public function sitemapAction()
          {
            $this->_helper->layout->disableLayout();
            $this->getResponse()->setHeader('Content-Type', 'text/xml; charset=utf-8');
          }    
    }

sitemap.phtml 中的代码:

<?php echo '<?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
      <url>
        <loc>http://www.example.com/home</loc>
        <priority>1.00</priority>
      </url>
      <url> etc...

在我的 routes.ini 中:

resources.router.routes.sitemap.type = "Zend_Controller_Router_Route"
resources.router.routes.sitemap.route = "/sitemap.xml"
resources.router.routes.sitemap.defaults.module = "default"
resources.router.routes.sitemap.defaults.controller = "sitemap"
resources.router.routes.sitemap.defaults.action = "sitemap"

根据之前的问题,控制器中的 disableLayout() 应该已经完成​​了,但对视图中的实际 xml 布局没有影响。

【问题讨论】:

  • 如果你查看XML的源代码,那是你想要的吗?
  • 是的,源代码没问题。

标签: xml zend-framework


【解决方案1】:

由于您设置了正确的内容类型,听起来这取决于您的浏览器选择呈现 XML 数据的方式。根据您使用的浏览器,您可能想看看是否可以找到一个可以为您提供更好的 XML 格式的扩展。

【讨论】:

  • 对于其他网站,我看到站点地图显示得很好,所以我认为这与浏览器无关? IE、Chrome 或 FF 也是如此。
  • 您能提供站点地图的网址吗?
  • @zef 你是怎么解决这个问题的,我也遇到了同样的问题。
  • @KasunRajapaksha 我实际上没有。 (chrome) 浏览器不呈现 xml 布局。因此,您可以尝试 Tim 在接受的答案中给出的建议,或者使用此处提到的 chrome 浏览器的扩展:superuser.com/questions/972/…
  • @zef 我通过附加 XML 的开源样式表解决了我的问题
猜你喜欢
  • 2013-12-23
  • 2019-08-18
  • 1970-01-01
  • 2021-05-23
  • 2011-05-13
  • 2014-08-08
  • 1970-01-01
  • 1970-01-01
  • 2011-04-14
相关资源
最近更新 更多