Welcome Guest, Not a member yet? Register   Sign In
My RSS feed is being interpreted as download?
#1

[eluser]taewoo[/eluser]
Hi all.

I followed Derek's tutorial on how to create RSS feed with CI. With my feed, i try to load it in the browser, the browser asks me to download.. Is this a header issue? (By the way... browser screenshot attached)

Controller:
Code:
$data['encoding'] = 'utf-8';        
$data['feed_name'] = 'RedMol.com';        
$data['feed_url'] = site_url();        
$data['page_description'] = 'Real Estate Cashflow Investments';        
$data['page_language'] = 'en-us';        
$data['creator_email'] = '[email protected]';        
$data['entries'] = $this->blog_model->get_any_blogs();          
header("Content-Type: application/rss+xml");        
$this->load->view('feed/rss', $data);

View
Code:
<?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<rss version="2.0"    
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"    
    xmlns:admin="http://webns.net/mvcb/"    
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"    
    xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>        
    
        &lt;title&gt;&lt;?= $feed_name; ?&gt;&lt;/title&gt;    
        &lt;link&gt;&lt;?= $feed_url; ?&gt;&lt;/link&gt;    
        <description>&lt;?= $page_description; ?&gt;</description>    
        <dc:language>&lt;?= $page_language; ?&gt;</dc:language>    
        <dc:creator>&lt;?= $creator_email; ?&gt;</dc:creator>    
        <dc:rights>Copyright &lt;?= gmdate("Y", time()); ?&gt;</dc:rights>
        &lt;?php foreach($entries as $entry){ ?&gt;            
            <item>          
                &lt;title&gt;&lt;?= xml_convert($entry->title); ?&gt;&lt;/title&gt;          
                &lt;link&gt;&lt;?= site_url('blog/user/'.$entry->user_name.'/'.date("Y/m/d/", $entry->created).url_title($entry->title) . $entry->title) ?&gt;&lt;/link&gt;          
                <guid>&lt;?= site_url('blog/user/'.$entry->user_name.'/'.date("Y/m/d/", $entry->created).url_title($entry->title) . $entry->title) ?&gt;</guid>          
                <pubDate>&lt;?= date ('r', $entry->created);?&gt;</pubDate>        
            </item>            
        &lt;?php } ?&gt;        
    </channel>
</rss>
#2

[eluser]benofsky[/eluser]
Hi, try this for the header instead:

Code:
header("Content-Type: application/xml");

Since as far as I know application/rss+xml doesn't exist (from my research).

Good luck
#3

[eluser]taewoo[/eluser]
Thans Ben...

But now I get this error (from FireFox .... IE just doesnt't display at all)
Code:
XML Parsing Error: xml declaration not at start of external entity
Location: http://localhost/feed/rss/user/taewoo
Line Number 1, Column 2: &lt;?xml version="1.0" encoding="utf-8"?&gt;<rss version="2.0"    
-^
#4

[eluser]taewoo[/eluser]
Ok I think I got it.
Spaces. Damn spaces in the controller causing all sorts of weird behavior.
#5

[eluser]alectrash[/eluser]
My solution is to get rid of the xml declaration at start of the doc here
Code:
&lt;?xml version='1.0' ?&gt;
Also make sure the mime type header goes in the controller.
Code:
header('Content-Type: text/xml; charset=utf-8');
     $this->load->view('blog_rss', $data);


The feed will still validate according to www.feedvalidator.org and validator.w3.org. Problem solved?
#6

[eluser]taewoo[/eluser]
hey alectrash
It was space issue. For some reason if you have spaces outside of XML tags, it causes this problem...
#7

[eluser]alectrash[/eluser]
Sorry it is a space issue correct, yes. I was just simply pointing out that removing the xml declaration solves the problem.

Have you found a way to solve the problem and keep the xml declaration by any chance. If so could you specify. Would be very much appreciated.
#8

[eluser]taewoo[/eluser]
this works for me
Code:
&lt;?php
    $this->load->helper('xml');
    echo "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;";
?&gt;
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        &lt;title&gt;&lt;?= $feed_name; ?&gt;&lt;/title&gt;
        &lt;link&gt;&lt;?= $feed_url; ?&gt;&lt;/link&gt;
        <description>&lt;?= $page_description; ?&gt;</description>
        <dc:language>&lt;?= $page_language; ?&gt;</dc:language>
        <dc:creator>&lt;?= $creator_email; ?&gt;</dc:creator>
        <dc:rights>Copyright &lt;?= gmdate("Y", time()); ?&gt;</dc:rights>
        &lt;?php foreach($entries as $entry){ ?&gt;
            <item>
                &lt;title&gt;&lt;?= xml_convert($entry->title); ?&gt;&lt;/title&gt;
                &lt;link&gt;&lt;?= site_url().blogURL($entry) ?&gt;&lt;/link&gt;
                <guid>&lt;?= site_url(). blogURL($entry) ?&gt;</guid>
                 <description>&lt;![CDATA[      &lt;?= $entry->body ?&gt;      ]]></description>
                <pubDate>&lt;?= date ('r', $entry->created);?&gt;</pubDate>      
            </item>
        &lt;?php } ?&gt;      
    </channel>
</rss>
#9

[eluser]alectrash[/eluser]
That :-) excellent thanks taewoo.




Theme © iAndrew 2016 - Forum software by © MyBB