how to generate RSS for news sites programmatically? I dont know how to start..
+1
A:
I learned how to write RSS from this article:
http://www.petefreitag.com/item/465.cfm
You can also just go to an RSS feed you like and press "View Source". Then you should simply use your java application to reproduce an XML similar to the XML you see (Only with your data).
When you finish, use one of many RSS Validators to validate your RSS.
It's easier than it first looks...
Faruz
2009-12-15 05:36:04
thank you..How can update autmatically when the new content is posted in my server
Senthil
2009-12-15 05:46:25
If the RSS is running against your database, it will update automatically every time a client requests it.
Faruz
2009-12-15 05:48:32
Bear in mind that the RSS doesn't have to be a xml file per-se. It can be a java file that creates an xml.
Faruz
2009-12-15 05:49:09
i.e. http://www.moviez.4pu.com/moviezrss.aspx is an rss feed with .aspx extension.
Faruz
2009-12-15 05:50:54
for ex if news site created new items or news's then how can I make it automaticaly updte it in my rss server? Shall I start autmatic check of those sites by every 5 minutes like that? Is there anyother way?
Senthil
2009-12-15 05:51:36
You can re-generate the rss every time you load the rss feed. (You can use cache if you want it to work faster).
Faruz
2009-12-15 06:18:07
Ok.Thanks I wll do that
Senthil
2009-12-23 10:04:16
A:
This code shows how to query a database to generate arbitrary XML from a JSP, manually.
It's not RSS, but the idea might be helpful to you.
private String ExecQueryGetXml(java.sql.PreparedStatement stmt, String rowEltName) {
String result= "<none/>";
String item;
java.sql.ResultSet resultSet;
java.sql.ResultSetMetaData metaData ;
StringBuffer buf = new StringBuffer();
int i;
try {
resultSet = stmt.executeQuery();
metaData= resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
String[] columnNames = new String[numberOfColumns];
for( i = 0; i < numberOfColumns; i++)
columnNames[i] = metaData.getColumnLabel(i+1);
try {
// if ((root!=null) && (!root.equals("")))
// buf.append('<').append(root).append('>').append('\n');
// each row is an element, each field a sub-element
while ( resultSet.next() ) {
// open the row elt
buf.append(' ').append('<').append(rowEltName).append(">\n");
for( i= 0; i < numberOfColumns; i++) {
item = resultSet.getString(i+1);
if(item==null) continue;
buf.append(" <").append(columnNames[i]).append('>');
// check for CDATA required here?
buf.append(item);
buf.append("</").append(columnNames[i]).append(">\n");
}
buf.append("\n </").append(rowEltName).append(">\n");
}
// conditionally close the row elt
// if ((root!=null) && (!root.equals("")))
// buf.append("</").append(root).append(">\n");
result= buf.toString();
}
catch(Exception e1) {
System.err.print("\n\n----Exception (2): failed converting ResultSet to xml.\n");
System.err.print(e1);
result= "<error><message>Exception (2): " + e1.toString() + ". Failed converting ResultSet to xml.</message></error>\n";
}
}
catch(Exception e2) {
System.err.print("\n\n----Exception (3).\n");
System.err.print("\n\n----query failed, or getMetaData failed.\n");
System.err.print("\n\n---- Exc as string: \n" + e2);
System.err.print("\n\n---- Exc via helper: \n" +
dinoch.demo.ExceptionHelper.getStackTraceAsString(e2));
result= "<error><message>Exception (3): " + e2 + ". query failed, or getMetaData() failed.</message></error>\n";
}
return result;
}
Cheeso
2009-12-15 07:00:12