If you are reading this, please get modern browser.
skip to main content | skip to main navigation | skip to secondary content

A few fixes for your RSS feed

~ 30th June 2005. · 00:32 CET · permanent link · printer friendly ~

Thanks to faithful readers Louis and Daniel, I fixed my feed, which wasn’t recognized by certain RSS aggregators. I also apologize for inconvenience to all of you who had such problems. My FeedDemon will digest anything, so I had no clue something’s wrong. Anyway, shame on me.

Incorrect header syntax

The problem was in incorrectly labeled header Last Modified, which is correctly spelled Last-Modified (with dash). In case you missed that lesson, a HTTP header field name can not contain spaces. For example, the Content-Type is correct, the Content Type is incorrect. Also from the HTTP specs:

“Any header fields which are not understood should be ignored.”

CDATA—what it’s good for?

Some blog management systems output feeds with a post content within legible opening <content:encoded> and closing </content:encoded> tags. This way the original HTML structure (with its’ elements like headings or paragraphs) can be preserved and viewed in your favorite RSS reader. Since XML syntax is very strict, one must also escape those tags by placing <![CDATA[ before and ]]> after the content, so XML processor knows those tags are not part of the XML structure.

“CDATA sections MAY occur anywhere character data may occur; they are used to escape blocks of text containing characters which would otherwise be recognized as markup. CDATA sections begin with the string <![CDATA[ and end with the string ]]>

Absolute vs. relative paths

If you run your feed through Feed Validator, it might throw you an error regarding relative paths to your images or files. This can be fixed by simple preg_replace() snippet, for example:

<?php
    echo '<content:encoded><![CDATA[';
    echo preg_replace('/<(img src|a href)="\//si', '<$1="http://' . $_SERVER['HTTP_HOST'] . '/', $content);
    echo ']]></content:encoded>';
?>

The above ensures that every <img src="/image.jpg" /> is replaced with <img src="http://yoursite.com/image.jpg" /> and also <a href="/file.zip" /> is replaced with <a href="http://yoursite.com/file.zip" />. If you use different paths, for example ../../image.jpg, the above will not work (actually it might break everything), but you’ve got starting point to tweak it to your needs. Read more about preg_replace() in PHP manual.

7 Comments

  1. I’m on the verge of unsubscribing, because when I click through onto articles like this:

    http://www.maratz.com/blog/archives/2005/06/28/funny-teasers/

    I don’t get any of the example images or anything - which is quite important to the article, wouldn’t you say? No, I’m not switching Referer on. You don’t need it.

  2. “No, I’m not switching Referer on.”

    And that is your choice with which I’m perfectly okay : )

  3. Don’t get me wrong, I’m not telling you to or threatening to leave :). But it’s an unnecessary annoyance and if it unnecessarily annoys me again, I’ll just give up and unsubscribe. And that’s my choice, and I’m sure you are perfectly okay with that too :).

  4. Wow, that was fast! I just emailed you this morning and not only a site fix but a write-up as well? I hope you have more bugs in this site . . .

  5. Dan, it’s never a question of not being able to handle things, but it’s often lack of extra few hours to seat down and fix the bug. Anyway, thanks again to you and Louis for reporting those issues.

  6. I’m puzzled by the use of ‘content’ namespace specified for RSS version 1.0 and not listed ‘compatible’ with RSS 2.0.

    Does declaring the namespace still help aggregators even in RSS 2.0? That shouldn’t be, since 1.0 isn’t valid 2.0 (but 0.91 and 0.92 are).

  7. I was wondering about this, thanks for the information.

Sorry, the comment form is closed at this time, but if you have anything to say, please send me a message.

* Please keep in mind that this is a personal web site and it does not reflect the position or opinion of my respective employers, organizations or partners.

Typetester – compare screen type Supported by Veer.

What is this?

A web log of Marko Dugonjić, web professional from Croatia. Topics covered:

Translate this site

German, Spanish, Italian, French or Japanese (via).

See you there!

Feel like buying a book?

Try with maratz.com aStore

Worth visiting

top of the page | skip to main content | skip to main navigation | skip to secondary content