dots Created with Sketch.
Yogesh Chauhan's Blog

A Step by Step Guide to Make RSS in XML For Any Website or Blog For Free

in Miscellaneous on December 27, 2019

In this article I will show you how you can generate your own RSS for your website or blog rather than using any paid service. It will take some time but you can do it.

What is RSS btw?

RSS = Really Simple Syndication (you might not find it simple though)

It allows you to promote your website content using it's already defined format for headlines and content. It's written in XML. You can personalize views for your different websites, the way you want.

Why do we need RSS?

Just imagine a scenario in which your beloved readers have to visit your website or blog every single time to check if you have posted anything new! Isn't that time consuming? RSS solves that problem. If you keep RSS feed on your website (on your server) and update it regularly then anyone can see what's new in there. There are many RSS readers available nowadays and they can format the data in a pretty amazing way.

If your website is updated frequently then I recommend you should use keep RSS feed like I have. (yogeshchauhan.com/rss.xml)

Let's see how to make RSS in XML

The basic format of RSS is like:


<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">

<channel>
  <title></title>
  <link></link>
  <description></description>
  <item>
    <title></title>
    <link></link>
    <description></description>
  </item>
  ........
  ........
</channel>
</rss>

The first line in the code above defines the XML version and character encoding used in the XML document. The second line specifies that it's an RSS document and version is 2.0

The next line is <channel> which we use to specify details about the channel AKA website AKA blog. Inside the <channel> element, there are 3 required elements we need to place.

  1. <title> : We specify main website's name for example, "The Coding Yogi".
  2. <link> :  We specify link associated with the website in this element
  3. <description> :  A small description about the website in this element

The next one is the series of <title> tags. That means depending on number of articles you have, you're going to need same number of <title> tags for your articles only. If you add extra links other than articles, for example, about us, you're going to need more <title> tags.

Each <item> tag requires 3 child elements as well.

  1. <title> : We specify the title of the blog post or article in this element 
  2. <link> :  We specify link associated with that article in this element
  3. <description> :  A small description about the article or blog post in this element

After the </description> closing tag we close the </item> tag and we open new <item> tag for new article details.

When you're done adding all your articles in <item> tag, you need to close the <channel> and <rss> elements.

REMEMBER: RSS is written in XML so all the elements MUST have a closing tag and they all are case sensitive. Attributes values need to be properly quoted and all the elements must be properly nested. 

Take a look at my small RSS from this website itself in the code below.


<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>The Coding Yogi Blog</title>
<link>http://www.yogeshchauhan.com/blog</link>
<description>
The Coding Yogi Blog Feed. Free Web Development Articles.
</description>
<item>
<title>
Learn to Establish Connection using MySQLi (object-oriented), MySQLi (procedural) and PDO with Example Code
</title>
<link>
http://www.yogeshchauhan.com/88/php/learn-to-establish-connection-using-mysqli-object-oriented-mysqli-procedural-and-pdo-with-example-code-by-yogesh-chauhan-the-coding-yogi-2019
</link>
<description>
In this article I will explain creating connections to MySQL databases using different PHP Database APIs
</description>
</item>
</channel>
</rss>

You can always validate your XML files on this website : https://validator.w3.org/feed/

So, that was it. You can share RSS feed with your viewers and readers via your website. You can also upload your RSS file to many search engines as well.

If you want to go ahead and include some more information in your RSS feed then you can. There are all other information you can include in your RSS feed such as category, author, image etc.

This is the code for adding more information into your <channel> tag:


<channel>
<title>The Coding Yogi Blog</title>
<link>http://www.yogeshchauhan.com/blog</link>
<description>
The Coding Yogi Blog Feed. Free Web Development Articles.
</description>
<image>
<title>The Coding Yogi Blog</title>
<url> http://www.yogeshchauhan.com/favicon.png </url>
<link>http://www.yogeshchauhan.com/blog</link>
</image>
<pubDate>Fri, 18 Oct 2019 12:29:00 CST </pubDate>
<ttl>180</ttl>
<language>en-us</language>
<copyright>2019 Yogesh Chauhan. All rights reserved.</copyright>
<webMaster>[email protected] (Yogesh Chauhan)</webMaster>

As you can see I've <image> tag after <description> tag. It allows an image to be displayed.

<image> tag requires 3 child elements:

  1. <link> : link for the website that offers the channel
  2. <title> : It displays title if the image could not be shown for some reason. It's like "Alt" attribute in HTML image element.
  3. <url> : URL associated with the image

Next one, I have is <pubDate> which defines last publication date for the content. All of my articles have the publication date in RSS feed and on my website.

I've <ttl> which specifies the number of minutes the feed can stay cached before refreshing it from the source.

Next one is <copyright> for copyright purposes.

And lastly, I have <webMaster> in which I have provided my contact address as an email address to the webmaster of the feed.

The same way you can add many more tangs to <title> tag as well to make your RSS feed a bit advanced. 

Here is the full sample of my RSS feed which you can learn from:


<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>The Coding Yogi Blog</title>
<link>http://www.yogeshchauhan.com/blog</link>
<atom:link href="http://www.yogeshchauhan.com/rss.xml" rel="self" type="application/rss+xml"/>
<description>
The Coding Yogi Blog Feed. Free Web Development Articles.
</description>
<image>
<title>The Coding Yogi Blog</title>
<url> http://www.yogeshchauhan.com/images/favicon.png </url>
<link>http://www.yogeshchauhan.com/blog</link>
</image>
<pubDate>Fri, 18 Oct 2019 12:29:00 CST </pubDate>
<ttl>180</ttl>
<language>en-us</language>
<copyright>2019 Yogesh Chauhan. All rights reserved.</copyright>
<webMaster>[email protected] (Yogesh Chauhan)</webMaster>
<item>
<title>
<![CDATA[
Learn to Establish Connection using MySQLi (object-oriented), MySQLi (procedural) and PDO with Example Code
]]>
</title>
<link>
http://www.yogeshchauhan.com/88/php/learn-to-establish-connection-using-mysqli-object-oriented-mysqli-procedural-and-pdo-with-example-code-by-yogesh-chauhan-the-coding-yogi-2019
</link>
<guid>
http://www.yogeshchauhan.com/88/php/learn-to-establish-connection-using-mysqli-object-oriented-mysqli-procedural-and-pdo-with-example-code-by-yogesh-chauhan-the-coding-yogi-2019
</guid>
<category>php</category>
<description>
<![CDATA[
In this article I will explain creating connections to MySQL databases using different PHP Database APIs
]]>
</description>
<pubDate>Wed, 16 Oct 2019 12:00:00 +0000</pubDate>
<enclosure url="http://www.yogeshchauhan.com/images/php/learn-to-establish-connection-using-mysqli-object-oriented-mysqli-procedural-and-pdo-with-example-code-by-yogesh-chauhan-the-coding-yogi-2019.png" length="1" type="image/png"/>
</item>
</channel>
</rss>
amazon

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Jul 22 Is there a CSS parent selector? #Jul 22 Difference between :where and :is in CSS #Jul 22 Does :is() pseudo selector hint at CSS preprocessing in the future? #Jul 22 Control Scrolling with CSS Scroll Snap #Jul 21 Control rendering using CSS content-visibility property #Jul 21 How to use @supports rule in CSS?
You might also like these
Solution for Xcode 11 Command PhaseScriptExecution failed with a nonzero exit code errorMiscellaneousHow to get recent posts in WordPress?WordPressWhat is IPS(Intrusion Prevention System), How Does It Work and What are the Detection Types?MiscellaneousWhat is an API?MiscellaneousSteps to Secure a VPNMiscellaneous3 Common Usability Mistakes In Web DesignUI/UX