RSS Development Tutorials

Source: Internet
Author: User
Tags add date format object contains unpack zip tld
rss| Tutorial RSS (Really Simple Syndication, a really easy chain) is a WEB content chain format. RSS becomes a standard format for WEB-linked news content. As part of a recent contract with Sun Microsystems, I am responsible for developing a "JSP tag library" that anyone who knows RSS, JavaServer Pages, and HTML can use. Taglib is primarily intended for non-technical editors of WEB sites that use RSS to collect news content. My goal is to develop a JSP tag library that will simplify the use of RSS content (versions 0.91, 0.92, and 2.0) in a Web page.

RSS Utilities Package is the result of this project. It includes a set of custom JSP tags that make up the RSS Utilities Tag library and the flexible RSS parser. This document describes how to use the parser and RSS Utilities Package to provide libraries. Click here to download the first version. The zip file contains a jar file Rssutils.jar (which contains the classes needed to use the tool) and a TLD file that defines a JSP custom label that extracts information from an RSS document.

Install Taglib

Although it is easy to use a tag library, it is required at installation time to understand how the WEB server works and how to configure it. The first step is to download and unpack the package. Once the zip file has been uncompressed, place a copy of Rssutils.jar and Rsstaglib.tld in the/web-inf/lib directory of the WEB application. Add the following taglib definition to the/web-inf/web.xml file for the WEB application:
<taglib>
<taglib-uri>/WEB-INF/rssutils.tld</taglib-uri>
<taglib-location>/WEB-INF/rssutils.tld</taglib-location>
</taglib>

Using Taglib

Once the taglib has been installed in the WEB application, follow these steps to use taglib in the JSP page. First, add the following line to the top of the JSP page:
<%@ taglib uri="/WEB-INF/rssutils.tld" prefix="rss" %>
Second, use the Feed tab to add the RSS feed to the JSP page, as shown in the following example:
<rss:feed url="http://servlet.java.sun.com/syndication/rss_java_highlights-10.xml" feedId="javaSunCom"/>
The URL property of the feed label must be included in the URL of the RSS document. The Feedid property of the Feed tab is arbitrary and can be set to any value. However, we recommend that the attribute be intuitive when identifying the RSS feed. If your application is behind a firewall, you can set agent properties by using the Feed label Agent property named ProxyAddress and ProxyPort. If you do not know the proxy server address proxy port, contact your network administrator. Here is an example:
<rss:feed url="http://servlet.java.sun.com/syndication/rss_java_highlights-10.xml" feedId="example1" proxyAddress="129.149.246.4" proxyPort="8080"/>
Once you add one or more RSS feeds to a page, you should be able to use the remaining set of tags to extract almost any information from the feed. Here is an example of how to extract the title of the RSS feed channel added above:

<rss:channeltitle feedid= "javasuncom"/>

Taglib sample

Example 1 (RSS 0.91):
<rss:feed
Url= "Http://servlet.java.sun.com/syndication/rss_java_ Highlights-xyzcompany-10.xml "
feedid=" example1 "/>
<b>image: </b><rss:channelimage feedId = "Example1" aslink= "true"/><br>
<b>title: </b><rss:channeltitle feedid= "example1"/> <br>
<b>link: </b><rss:channellink feedid= "example1" aslink= "true"/><BR>
< B>description: </b><rss:channeldescription feedid= "example1"/><BR>
<ul>
<li ><rss:itemtitle feedid= "example1" index= "0"/><BR>
<rss:itemdescription feedid= "example1" index= "0"/><br><br>
<li><rss:itemtitle feedid= "example1" index= "1"/><BR>
<rss:itemdescription feedid= "example1" index= "1"/><BR>
</ul>

Example 2 (RSS 0.92):
<rss:feed
url="http://static.userland.com/gems/backend/gratefulDead.xml" feedId="example2"/>
<b>Image: </b><rss:channelImage feedId="example2"/><br>
<b>Title: </b><rss:channelTitle feedId="example2"/><br>
<b>Link: </b><rss:channelLink feedId="example2" asLink="true"/><br>
<b>Description: </b><rss:channelDescription feedId="example2"/><br>
<ul>
<rss:forEachItem feedId="example2">
<li><rss:itemDescription feedId="example2"/><br><br>
</rss:forEachItem>
</ul>

Example 3 (RSS 2.0):
<rss:feed
Url= "Http://static.userland.com/gems/backend/rssTwoExample2.xml"
Feedid= "Example3"/>
<b>image: </b><rss:channelimage feedid= "Example3"/><br>
<b>title: </b><rss:channeltitle feedid= "Example3"/><br>
<b>link: </b><rss:channellink feedid= "Example3" aslink= "true"/><br>
<b>description: </b><rss:channeldescription feedid= "Example3"/><br>
<b>copyright: </b><rss:channelcopyright feedid= "Example3"/><br>
<b>docs: </b><rss:channeldocs feedid= "Example3"/><br>
<b>generator: </b><rss:channelgenerator feedid= "Example3"/><br>
<b>language: </b><rss:channellanguage feedid= "Example3"/><br>
<b>last Build Date: </b><rss:channellastbuilddate
X-virus:1
Feedid= "Example3"/><br>
<b>managing Editor: </b><rss:channelmanagingeditor
Feedid= "Example3"/><br>
<b>pub Date: </b><rss:channelpubdate feedid= "Example3"/><br>
X-virus:1
<b>skip days: </b><rss:channelskipdays feedid= "Example3"/><br>
<b>skip Hours: </b><rss:channelskiphours feedid= "Example3"/><br>
<b>ttl: </b><rss:channelttl feedid= "Example3"/><br>
<ul>
<rss:foreachitem feedid= "Example3" startindex= "2" endindex= "4" >
<li><rss:itemdescription feedid= "Example3"/><br><br>
</rss:forEachItem>
</ul>

How to use Rssparser?

In a way, the parser is a by-product of the project. Although the parser is developed with a tag library, it is entirely self-contained and can be used in Java applications. However, to do this, it is clear that you need at least an understanding of how to write basic Java code. (If you know how to write Hello world in the Java language, there's no problem.) )

First download and unpack the package. Once you have added Rssutils.jar to your classpath, use Rssparserfactory to create an instance of the Rssparser interface: RssParser parser = RssParserFactory.createDefault();
Rss rss = parser.parse(new
URL("http://mydomain.com/document.rss"));

The parser-generated RSS object is the Java object representation of the RSS document that is located in the provided URL. Use the methods provided by the RSS object to get handles to other RSS objects, such as channels and Items. Rssparser can also parse File objects and InputStream objects.

Conclusion

RSS provides an easy way to add and maintain news and other content from all Web sites on your Web site. Even if RSS is a simple XML format, parsing and extracting data from an XML document anywhere else on the WEB can be tricky--or at least tedious--if you have to do it over and over again. RSS Utilities Package uses Custom Tag and XML parsing technology to make the real Simple syndication format truly the same as its name.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.