在Rss.xml文件中获取不需要的数据

I'm using codeigniter library and i use the code below to generate an xml rss feed file this is the controller code :

class Rssfeed extends MY_Controller {

public function Generate_rss_feed()
{
    $this->load->helper('visitors');
    $data['visitors'] = visitors_counter($this,$this->input->ip_address());
    $this->load->helper('xml');
    $this->load->helper('text');
    $this->load->model('news_model');

    $data['feed_name'] = 'MyWebsite.com'; // your website
    $data['encoding'] = 'utf-8'; // the encoding
    $data['feed_url'] = base_url().'index.php/rssfeed/Generate_rss_feed'; // the url to your feed
    $data['page_description'] = '';//some description
    $data['page_language'] = 'ar-ar'; // the language

    $data['posts'] = $this->news_model->get_latest_news(3);  
    header("Content-Type: application/rss+xml"); // important!  
    $data['mode']= 'rss_feed';
    $data['view_page']= 'rss';
    $this->load->view('rss', $data);
}
}

and in the view there are :

<html>
<head>
     <meta charset="UTF-8">
</head>
<body>

<?php  

$rss_feed = '<?xml version="1.0" encoding="' . $encoding . '"?-->' . "
".'
<rss version="2.0"   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >

<channel>
<title>'.$feed_name.'</title>

<link>'.$feed_url.'
<description>'. $page_description.'</description>
<dc:language>'. $page_language.'</dc:language>


<dc:rights>Copyright'. gmdate("Y", time()).'</dc:rights>
<admin:generatoragent rdf:resource="http://www.codeigniter.com/">';
foreach($posts as $post){ 

    $rss_feed .='<item>
      <title>'.xml_convert($post->Title).'</title>
      <link>'.site_url('blog/posting/' . $post->ID).'</link>
      <guid>'. site_url('blog/posting/' . $post->ID).'</guid>
      <description>'.$post->Head_line .'</description>
        <pubdate>'.date("F j, Y, g:i a",$post->Date).'</pubdate>
    </item>';


}  
$rss_feed .= ' </admin:generatoragent></channel>
</rss>';
force_download('feed.xml', $rss_feed);
?>
</body>
</html>

the problem is when i download the xml file it contains :

<html>
<head>
<meta charset="UTF-8">
</head>
<body>

and i don't know where it comes from ? any help ..

from the view file, remove these lines in your code.

  • Line 1 < html>
  • Line 2 to Line 6
  • Line 38
  • Line 39 < /html>