Question : Zend sitemap.xml rendering inside <html>tags - how do I escape or context switch?

I have created a sitemap.xml with Zend framework using Zend_Navigation. When I go to my sitemap.xml page the sitemap is being correctly built but renders inside <html> and <body> tags so I don't get the proper formatting for the xml document.

I've tried contextSwitch and routing but can't seem to get it to work.

The sitemap.xml url is http://www.stagedive.com/sitemap.xml

Below is the code
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
public function init() {

		$this->_helper->contextSwitch()
			->addContext(
				'txt', array('suffix'=>'txt', 'headers'=>array('Content-Type'=>'text/plain'))
				)
				->addActionContext('robots','txt')
				->addActionContext('sitemap','xml')
				->initContext();
	}
	
	public function indexAction () {
		$this->_helper->layout()->disableLayout();
		//$this->_helper->viewRenderer->setNoRender(true);
		$pages = array(
			array(
		        'label'      => 'Home',
		        'title'      => 'Home',
		        'module'     => 'default',
		        'controller' => 'index',
		        'action'     => 'index',
		        'order'      => -100, // make sure home is the first page
		        'lastmod'	=> '2010-06-29T08:15:30-08:00',
				'changefreq'	=>	'daily',
				'priority'	=> '1'
		    ),
		    array(
		        'label'      => 'Bands',
		        'module'     => 'default',
		        'controller' => 'band',
		        'action'     => 'list',
		        'visible'    => true,
				'lastmod'	=> '2010-06-29T08:15:30-08:00',
				'changefreq'	=> 'daily',
				'priority'	=>	'1'
		    ),
			array(
		        'label'      => 'Assets',
		        'module'     => 'default',
		        'controller' => 'asset',
		        'action'     => 'list',
		        'visible'    => true,
				'lastmod'	=> '2010-06-29T08:15:30-08:00',
				'changefreq'	=> 'daily',
				'priority'	=>	'1'
		    ),
			array(
		        'label'      => 'Venues',
		        'module'     => 'default',
		        'controller' => 'venue',
		        'action'     => 'list',
		        'visible'    => true,
				'lastmod'	=> '2010-06-29T08:15:30-08:00',
				'changefreq'	=> 'daily',
				'priority'	=>	'1'
		    ),
			array(
		        'label'      => 'Help',
		        'module'     => 'default',
		        'controller' => 'content',
		        'action'     => 'help',
		        'visible'    => true,
				'lastmod'	=> '2010-06-29T08:15:30-08:00',
				'changefreq'	=> 'monthly',
				'priority'	=>	'0.8'
		    )
		);
		
		$container = new Zend_Navigation($pages);
		$this->view->navigation($container);
	}


VIEW index.phtml
<?
echo $this->navigation()->sitemap();
?>

Answer : Zend sitemap.xml rendering inside <html>tags - how do I escape or context switch?

if you write a sitemap controller the results are:

www.yourdomain.com/sitemap/xml

where xml is an action like xmlAction...

You have to set the 'Content-Type' response header to 'text/xml' for sitemap.xml.

For robots.txt the action is robotsTxtAction() with text/plain content type.
Random Solutions  
 
programming4us programming4us