RSS is an XML feed, so to generate a valid RSS programmatically, you need to understand the RSS 2.0 Specification.
Lets first see how a RSS XML is structured.
The XML consists of two set of sections.
<channel></channel><item></item> The purpose of Channel element is to define the overall website information. so, the following elements
    are required.
title - Title of your website. REQUIRED.link - Link to the posts. REQUIRED.description - A HTML content of the page. If the page has the HTML content, wrap it within <![CDATA[your html content]]> REQUIRED.pubDate - Publication date for the post in RFC 822.OptionalThere are also other elements like image, category, generator and others but
    they are optional. Pick as you see it fit.
Here again elements like title, description and link are REQUIRED.
    Item provides the information about the individual posts that goes into the website. So, we need to
    create
    item per posts that our website contains. There is no limit to the number of item a channel
    can contain.
Once you publish a new blog post, you need to update both sitemap.xml and your rss.xml.
    Next add the reference to the rss on the index page -
    <link rel="alternate" type="application/rss+xml" href="https://example.org/rss.xml" title="Example site">.
Once you generate the RSS, you can validate it using Feed Validator, W3C Feed Validation or any other relevant RSS validators.
For my new posts, Subscribe via weekly RSS, common RSS