2013-10-05 22 views
1

我要顯示我在正確的XML格式的網站地圖,但它顯示在同一行:XML網站地圖的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佈局沒有影響。

+0

如果您查看XML的來源,那麼它是如何呢? –

+0

在源代碼中可以。 – zef

回答

0

由於您正在設置正確的內容類型,這聽起來像是您的瀏覽器選擇呈現XML數據的方式。根據您使用的瀏覽器,您可能想要查看是否可以找到能夠爲您提供更好的XML格式的擴展。

+0

對於其他網站,我看到站點地圖很好地顯示,所以我不認爲它與瀏覽器有什麼關係? IE,Chrome或FF也是如此。 – zef

+0

你可以提供你的網站地圖的網址? –