Grab Headlines From A Remote RSS File
By Nicholas Chase2003-12-19
Choosing A Version
As long as you're allowing for different formats, you can actually create a system that checks for the feed version before processing it. After all, only RSS 1.0 and 2.0 feeds can have RDF elements, so there's no need to process other feeds. But how can you tell what version to apply?
To solve this problem, you can load the actual feed, analyze it, and use the information to set the proper stylesheet.
Listing 9. Choosing a stylesheet
|
In this case, you're loading the feed and checking it for the RSS version, and then using the version number as the file name. The advantage here is that should a new version of RSS be released, you can extend the application by simply adding a new stylesheet. Notice that I've added a check for Echo, or Atom, or whatever RSS's competitor might eventually be called, and that you can also adjust support for it as it changes by simply changing the echo.xsl stylesheet.
The advantage here is that this interim stylesheet is completely generic. A "2.0 - .91" stylesheet will work for anyone, anywhere, and you can make changes to the final output by simply editing final.xsl, whether you support one version or a hundred.
The final.xsl stylesheet is designed for a simple 0.91-style feed, so if you're dealing with one, you'll omit the stylesheet on the interim transformation. This creates an identity transform, in which the document is simply passed along as-is.
That takes care of the problem of multiple versions, but you have one more issue to deal with: concurrency.
Tutorial Pages:
» Retrieve Syndicated Content, Transform It, & Display The Result
» The Source File
» The Primary Stylesheet
» The Basic JSP Page
» Transforming The File
» Adjusting For Multiple Formats
» Choosing A Version
» Caching The Feed
» Conclusion
» Resources
First published by IBM developerWorks
