6

I have a list if these 3 items: title and link and a html based description and I am looking for a library or external tool which can be fed these 3 items and create a rss xml page. Does such a thing exist?

3 Answers 3

13

I suggest you use a template and feed the list of items to the template.

Example Jinja2 template (Atom, not RSS, but you get the idea), assuming that the items are 3-tuples (title, link, html):

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <author>Author's name</author>
    <title>Feed title</title>
    {%for item in items %}
    <entry>
        <title>{{item[0]}}</title>
        <link href="{{item[1]}}"/>
        <content type="html">{{item[2]}}</content>
    </entry>
    {%endfor%}
</feed>

Code to feed content to the template and output the result:

import jinja2
env = jinja2.Environment(loader=jinja2.FileSystemLoader("."))
print env.get_template("feedtemplate.xml").render(items=get_list_of_items())
Sign up to request clarification or add additional context in comments.

2 Comments

If item[0] or item[2] contains an HTML entity that does not exist in XML (such as ©), then your feed would not be well-formed. See alexatnet.com/articles/…
But you normally wouldn't have HTML entities in the title or html. You would have normal unicode strings.
2

How about django's RSS Framework?

Comments

1

This might not be the answer you search for, but any RSS dialect is a fairly simple standard (holding for 0.9 and 2 especially, and with constraints for 1, too).

You could consider writing it by hand, if you don't have any additional constraints (like, you already use Django, or it will get more complex in the nearer future, or it should automatically be distributed, or you want to create RSS 1, RSS 2 and Atom all at once and don't have the time to read 3 specs).

Specifications:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.