XML Generator - Plan of Attack

  • Thread starter Thread starter jay
  • Start date Start date
J

jay

Hello all,

I'd like to probe the community for some insight, if I may. I am in the
planning stages of developing an XML generator for my workplace.

Our site has an internal news system which stores news items as
database entries. Our head organization has requested that all branches
make an rss or xml file available for syndication on their central news
site. I'm curious as to what plan of attack would be best suited for
this application.

I'm working in VS.NET 2003, Windows 2000, SQL Server 2000.

Web service, ASPNET page? How about caching? Any thoughts or insights
would be helpful. Thanks for your time! :)

-Jay
 
Jay,

Well, first, I would look for something that already generates RSS
documents. If I recall correctly, dot net nuke has an RSS component which
you could use.

Even so, from what I know, RSS doesn't have a terribly complex schema,
so you could generate it on your own, if you wish. You just have to choose
how much you are going to pipe (you can't very well pipe everything on each
request, you need to stop somewhere).

As for distribution, I don't think that a web service is appropriate
here. The reason for this is that the delivery of RSS feeds is already set,
and it's a simple XML result over an HTTP request. A web service would
complicate that needlessly.

Hope this helps.
 
How often does the news change?

I assume that you will give the location of the file to the head
organisation who will grab it occasionally?

The simplest way would be to spit out a static .xml/.rss file whenever the
news is changed. Could this be added to the news system, i.e. do you have
access to the source of it, or would it need to be a separate little
app/service that polls the database occasionally?

Jevon
 
Thanks for the input!
As for distribution, I don't think that a web service is appropriate
here. The reason for this is that the delivery of RSS feeds is already set,
and it's a simple XML result over an HTTP request. A web service would
complicate that needlessly.

That makes sense.
How often does the news change?

Only a few times a day.
I assume that you will give the location of the file to the head
organisation who will grab it occasionally?
Exactly.

The simplest way would be to spit out a static .xml/.rss file whenever the
news is changed. Could this be added to the news system, i.e. do you
have access to the source of it, or would it need to be a separate little
app/service that polls the database occasionally?

I have all of the source. It probably would be simple to create a class
that generates a "top 10 news posts" XML file and then call that every
time someone adds a news item. That would also ensure that the file is
always up-to-date.
 
I would go with pure XML. You can then output it as any format you choose,
RSS, HTML, Text, and any other document format you choose, by applying XSL
transforms on it.

It might be good to generate this XML with a serialzable class. The class
could query the database to populate itself, and then serialze itself to a
string, a stream, a file, etc.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
As Nicholas says, RSS is simple enough and you can create an RSS feed
easily.

It should be a XML response to an HTTP request and I format only the last 10
entries in my feeds and expect the RSS reader to cache the entries it has
seen. If you turn the RSS reader off for a period of time longer than the
distribution rate you're probably not going to be vastly interested in the
"news" anyway.

After my signature is a listing for a simple RSS feed provider that I use on
one of my sites... It's quick and dirty but it seems to work fine.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

/// <summary>

/// Summary description for rss.

/// </summary>

public class rss : System.Web.UI.Page

{


private void Page_Load(object sender, System.EventArgs e)

{


}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

protected override void Render(HtmlTextWriter writer)

{

this.Response.ContentType="application/xml";

OleDbConnection cnx=new
OleDbConnection(Constants.NEWSConnectionString(Server));

OleDbCommand cmd=new OleDbCommand(@"SELECT TOP 10 newsitems.newsitemid,
newsitems.date, newsitems.title, newsitems.description

FROM newsitems

ORDER BY newsitems.date DESC;

",cnx);

cnx.Open();

OleDbDataReader rdr=cmd.ExecuteReader();

writer.WriteLine("<?xml version=\"1.0\"?>");

writer.WriteLine("<!DOCTYPE rss PUBLIC \"-//Netscape Communications//DTD RSS
0.91//EN\" \"http://my.netscape.com/publish/formats/rss-0.91.dtd\">");

writer.WriteLine(" <rss version=\"0.91\">");

writer.WriteLine(" <channel>");

writer.WriteLine(" <!-- Channel Information -->");

writer.WriteLine(" <title>Your newsfeed title goes here</title>");

writer.WriteLine(" <link>http://www.yourlink.com</link>");

writer.WriteLine(" <description>This is some blurb</description>");

writer.WriteLine(" <language>en-us</language>");

if(rdr.HasRows)

{

while(rdr.Read())

{

writer.WriteLine(" <!-- Item details -->");

writer.WriteLine(" <item>");

writer.WriteLine(string.Format("
<title>{0}</title>",rdr["title"].ToString()));

writer.WriteLine(string.Format("
<description>{0}</description>",rdr["description"].ToString()));

writer.WriteLine(string.Format("
<link>{0}?item={1}</link>",Constants.NewsContentUrl,
rdr["newsitemid"].ToString()));

writer.WriteLine(" </item>");

writer.WriteLine(" <!-- End Item details -->");

}

}

writer.WriteLine(" </channel>");

writer.WriteLine(" </rss>");

writer.Flush();

}
 
Wow guys! This is all great. I had been looking at using an XSLT to
convert a DataSet.GetXML file to the xml format requested by our head.
However, it might be simpler (as I'm not really familiar with XSLT) to
generate it on the fly directly from the database. Thanks again for all
of the great input.

I'm going to follow this thread for a while and see what options are
out there before I begin. :)
 
Bob,

The code you supplied works beautifully. It's always so helpful to have
a working example to go from when you are trying to learn something
new. My job provides a lot of book-type resources but it takes a while
to sift through them when I'm tackling a specific problem. Now I know
what I really need to brush up on. :)

Kevin,

Is a serializable class similar to the approach Bob suggested?
 
Back
Top