Generating RSS Feeds
RSS Feeds are inherently repeated patterns over and over again with a bit of text in the middle for a link and some content. So what’s the best way to generate one. I’ve debated this to my self now for a few days and can’t really come up with a strong enough argument to sway me one way or the other.
As I see it there are three realisting posibilities. These are….
- Generate the feed using print/sprintf statements. This has the advantage of being quick, having very little memory footprint and requiring less processing power. The major draw back is that the XML isn’t validated. Another drawback is that it won’t be the prettiest solution.
- Use a templating system. If you pick the right templating system this could be quite fast, with HTML::Templates caching for example this could be done fairly quickly and fairly painlessly. Again the big disadvantage is that the XML isn’t parsed and validated.
- Use an XML module such as XML::Simple or XML::Feed. XML::Feed you say, that sounds like it’s designed to do just the job. Well yes it is, but it aslo uses a full DOM to build up the feed, as would XML::Simple so it’s comparitively slow compared to the first two methods. The major advantage being that it would pretty much always generate validatable XML.
So with the first two sollutions we could generate the output and then validate it with an XML Parser to check it, but surely that takes away the major benifits of either sollution. If we use the templated sollution, so long as we ensure that the content within the template variables is XML friendly and in CDATA tags etc, surely we can guarantee that the XML output should be fine.
So do we go with a less elegant, more speedy sollution or a more elegant less speedy sollution. Of course we could cache the output of the more elegant sollution if the feed data wasn’t changing too often, making the argument a no brainer, but what if the data changes every few seconds…. I just can’t make up my mind.
1 comment
Go with the speedy solution , that’s the one that matters most to the end user, IMHO.
Leave a Comment