xml站点地图未以xml格式显示 [英] xml sitemap not displaying in xml format

查看:23
本文介绍了xml站点地图未以xml格式显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to display my sitemap in proper xml format but it displays in one line:

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 中的代码:

My code in 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 中的代码:

Code in 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 中:

In my 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 布局没有影响.

Based on earlier questions the disableLayout() in controller should have done it but has no effect on actual xml layout in view.

推荐答案

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

Since you're setting the correct content-type, it sounds like this is just down to how your browser is choosing to render XML data. Depending on what browser you're using, you might want to see if you can find an extension that will give you better XML formatting.

这篇关于xml站点地图未以xml格式显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆