RSS without limits: JERSS (2/2) - exploring XML
RSS without limits: JERSS
Using the servlet
The JERSS servlet takes two parameters, and returns JavaScript objects populated with information about the news headlines. The Web author can then use JavaScript and these populated objects to generate HTML that presents the headlines in whatever manner the author sees fit. This way the author has 100% control over the design of the presentation.
If you use the JERSS servlet to include at least one newsfeed in your Web page, you must include the following script tag in the HEAD of your HTML document:
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript" SRC="/path/to/rss.js"> </SCRIPT>
To add a newsfeed to your Web page, include the following tag in the HEAD of your HTML document (you should include one tag per channel you want to include - if you have three channels, you'll have three of these tags):
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript" SRC="/path/to/RSSViewerServlet?url=[RSS]&prefix=[x]"> </SCRIPT>
Replace [RSS] with the URL of the RSS newsfeed you want to include on your Web page. For example, if you want to include the latest stories from WebReference, you'd use the URL https://www.webreference.com/webreference.rss. Replace [x] with a prefix you'd like to use to uniquely identify the variables associated with this particular newsfeed. This is optional and is useful if you want to include multiple newsfeeds on one Web page.
To create HTML out of the JavaScript generated by the JERSS servlet, you'll need to write some JavaScript of your own. Exactly how you do this is up to you, because it will be unique to the design of your Website. However, there are some things to keep in mind:
- Information about the RSS channel is stored in an object called [prefix]channel. So, if you use "top" as the prefix parameter passed to the JERSS servlet, the object would be called topchannel. If you exclude the value of the prefix parameter (or the parameter altogether), then the object would be called channel. If you included two newsfeeds and used the prefix "top" for one and "phl" for the other, then there would be two objects, one named topchannel and the other named phlchannel.
- Channel has several properties, all of which may not be populated - it depends on the data provided in the specific RSS file. The properties available are channel.title, description, link, editor, Webmaster, copyright, and language.
- Information about the items in an RSS channel is stored in an array of objects called [prefix]items. If you use "top" as the prefix, the array is called topitems. If the prefix is "phl", the array is called phlitems. If you exclude the prefix, the array is called items.
- Each object in the items array has three properties: items[i].title, link, and an optional description.
- The number of items in the channel is stored in a variable called [prefix]NumberOfItems. If you use "top" as the prefix, the variable is called topNumberOfItems. If you exclude the prefix, the variable is called NumberOfItems.
Here's an example of some very simple JavaScript to produce some very simple HTML to display news headlines (it assumes the prefix "top" was used when including the channel):
<script> document.write( "<h2><a href='"+topchannel.link+"'>"+topchannel.title+"</a></h2><h3>"+ topchannel.description+"</h3>"); for (i=0; i<topNumberOfItems; i++){ document.write("<b><a href='"+topitems[i].link+"'>"+topitems[i].title+"</a></b><br>"+ topitems[i].description+"<br>"); } </script>
Conclusion
The servlet solution elegantly works around the access restrictions that are placed on applets and therefore the limits inherited by RSSApplet. The RSS information is handed to the browser as JavaScript data that can be inserted into the HTML page. This way integrating the RSS news feed into one's own site is seamlessly possible.
- For more examples and information see Jay Eckles' Web site .
- Get comprehensive information on RSS at WebReference.
Produced by Michael Claßen
URL: https://www.webreference.com/xml/column39/2.html
Created: Sep 16, 2001
Revised: Sep 16, 2001