.
Developer Spot - Web Development Tutorials
arrowDeverloper Spot  Tutorials  XML  Grab Headlines From A Remote RSS File 
 
Development Tutorials
ASP
CGI & Perl
CSS
HTML
Java
JavaScript
Linux
PHP
XML




More Resources
Web Hosting Articles
Web Development News
PHP Manual
Web Hosting Directory
Budget Web Hosting Linux Web Hosting Small Business Hosting
Windows Web Hosting Reseller Web Hosting Web Hosting Articles

Grab Headlines From A Remote RSS File

By Nicholas Chase
2003-12-19
Reader Rating: 4 out of 5
Bookmark Print Version
Transforming The File

The Java bean is nothing more than a Java class that has get and set methods. In this case, the set method, setRSSFile() also includes code that performs a transformation on that file:

Listing 5. Transforming the feed
import javax.xml.transform.stream.StreamSource;

import javax.xml.transform.stream.StreamResult;
import java.io.FileOutputStream;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;

public class RSSProcessor {

public RSSProcessor(){ }

String _RSSFile;

public String getRSSFile(){
return _RSSFile;
}

public void setRSSFile(String fileName){

try {

StreamSource source = new StreamSource(fileName);

StreamSource finalStyle = new StreamSource("final.xsl");

String outputURL = "headlines.html";
StreamResult result = new StreamResult(new
FileOutputStream(outputURL));

TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer(finalStyle);
transformer.transform(source, result);

} catch (Exception e) {
e.printStackTrace();
}
}


}


This method simply takes an input source, which happens to be a remote RSS feed, and transforms it, using the final.xsl stylesheet, to the headlines.html file.

In the grand scheme of things, that's it: Retrieve the file, transform it, and display the results. In reality, there are other issues to consider.


Article 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


 Rate this article:   Poor          Excellent 


If you found this article interesting, you may want to read these as well:

» Better SOAP Interfaces With Header Elements

» Variable Substitution In XML Documents

» Create JPEGs Automatically With SVG

» Tip: Convert from HTML to XML with HTML Tidy



 
Development Tutorials: CGI & Perl - CSS - HTML - Java - JavaScript - Linux - PHP - XML
More Resources: Web Hosting Articles - Web Development News - PHP Manual