RSS feed <> sql server <> aspx <> xml <> blog

G

Guest

I have been researching articles on google on how to create a simple RSS
feed that sucks <title><blurb><link><date> out of a sql server 2000 database
via an aspx page.

I know it has to be pushed into a <xml> document but not sure which
direction to take.

Is there perhaps a starter document which uses sql server as the data source
I can tap into.

I am a newbie to aspx but I it appears there is a lot of inbuilt support for
this application and I don't wish to go down to many wrong paths or reinvent
the wheel.

Any advice appreciated!

Jason

ps: It appears that <rss> is tied in heavily with <blogs> these days....is
anyone come up with a combined solution?
 
J

Jason Kester

Here's the meat of the the rss.aspx that I use for blogabond.com. As
you can see, it's just a single repeater dumping out XML instead of
HTML. Couldn't be much simpler, though you'll need to remember to set
the ContentType on the server:

Page.Response.ContentType = "text/xml";





<?xml version="1.0" ?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">
<channel>
<title>Blogabond.com - Livin' large in the third world</title>
<link>http://www.blogabond.com/</link>
<description>Travel journals and photo blogs from world travellers.
Maps, research and resources for the aspiring vagabond.</description>
<dc:language>en-US</dc:language>
<dc:creator></dc:creator>
<copyright>Copyright © 2005, Blogabond.com</copyright>
<sy:updatePeriod>daily</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<sy:updateBase>1</sy:updateBase>
<asp:Repeater ID="rptComments" Runat=server>
<ItemTemplate>
<item>
<title><%# DataBinder.Eval(Container.DataItem,
"CommentTitle")%></title>
<description><![CDATA[<%# GetDescription(
DataBinder.Eval(Container.DataItem, "CommentText"),
DataBinder.Eval(Container.DataItem, "UserID") )%>]]></description>
<author><%# GetAuthorName( DataBinder.Eval(Container.DataItem,
"UserID") )%></author>
<category><%# GetLocationName( DataBinder.Eval(Container.DataItem,
"LocationID") )%></category>
<pubDate><%# GetPubDate( DataBinder.Eval(Container.DataItem,
"CommentDate") )%></pubDate>
<link>http://www.blogabond.com/TripView.aspx?tripID=<%#
DataBinder.Eval(Container.DataItem, "TripID")%></link>
<guid
isPermaLink="true">http://www.blogabond.com/CommentView.aspx?commentID=<%#
DataBinder.Eval(Container.DataItem, "CommentID")%></guid>
<slash:comments>0</slash:comments>
</item>
</ItemTemplate>
</asp:Repeater>
</channel>
</rss>



Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
 
G

Guest

Dude, awesome - its been a long time since anyone has posted a full set of
example code for an inept <newbie /> such as myself. :)) Thanks!!

My first stupid question:

I sucked your code into aspx container page in web matrix (free) and tried
executing and obviously it generates a compile error with regards the
content type.

How do I actually insert the content type onto the page below?

I have done some searches on 'content type examples text/xml'.

I pick up a compilation error when I add this to the page:

<%Page ContentType="Text/Xml">

What am I doing wrong?
 
J

Jason Kester

That needs to live on the codebehind (or possibly in a <script
runat=server> if you're not using codebehinds). Here is a small chunk
of mine. Obviously you'll need to generate your own dataset to bind
the repeater, and you'll need to write your own helper functions to
format dates and HtmlEntityEncode strings:



protected Repeater rptComments;

private void Page_Load(object sender, System.EventArgs e)
{
Page.Response.ContentType = "text/xml";

DataView dv = TripReportComment.List().Tables[0].DefaultView;
dv.Sort = Comment.Columns.CommentDate + " desc";

rptComments.DataSource = dv;
rptComments.DataBind();

}



Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top