Rss Reader : RSS « Development « ASP.NET Tutorial

ASP.NET Tutorial
1. ASP.Net Instroduction
2. Language Basics
3. ASP.net Controls
4. HTML Controls
5. Page Lifecycle
6. Response
7. Collections
8. Validation
9. Development
10. File Directory
11. Sessions
12. Cookie
13. Cache
14. Custom Controls
15. Profile
16. Configuration
17. LINQ
18. ADO.net Database
19. Data Binding
20. Ajax
21. Authentication Authorization
22. I18N
23. Mobile
24. WebPart
25. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.NET Tutorial » Development » RSS 
9. 37. 2. Rss Reader
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="RssReader" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Rss Reader</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Panel ID="panSelect" 
               runat="server" 
               BorderWidth="1" 
               BorderStyle="Solid" 
               BackColor="Beige" 
               CssClass="SelectArea">
    <h1>RSS Reader</h1>
    Select a RSS feed<br />    
    <asp:DropDownList ID="drpFeeds" runat="server" >
      <asp:ListItem Value="http://rss.cnn.com/rss/cnn_topstories.rss">CNN</asp:ListItem>
      <asp:ListItem Value="http://msdn.microsoft.com/rss.xml">MSDN</asp:ListItem>
      <asp:ListItem Value="http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml">BBC Technology News</asp:ListItem>
    </asp:DropDownList>
    
    Select a template<br />
    <asp:DropDownList ID="drpTemplates" runat="server">
      <asp:ListItem Value="~/App_Data/RssTransform1.xsl">RssTransform 1</asp:ListItem>
      <asp:ListItem Value="~/App_Data/RssTransform2.xsl">RssTransform 2</asp:ListItem>
    </asp:DropDownList>
    
       
          <asp:Button ID="btnRead" runat="server" Text="Read Feed" OnClick="btnRead_Click" />
       
    </asp:Panel>
    
    <asp:Panel ID="panFeed" runat="server">
    <asp:Xml ID="myXml" runat="server"></asp:Xml>
    </asp:Panel>
    </form>
</body>
</html>

File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

public partial class RssReader : System.Web.UI.Page
{
    protected void btnRead_Click(object sender, EventArgs e)
    {
        string xmlUrl = drpFeeds.SelectedValue;
        XPathDocument xpdoc = new XPathDocument(xmlUrl);
        XPathNavigator xnav = xpdoc.CreateNavigator();

        myXml.XPathNavigator = xnav;

        string xslFilename = drpTemplates.SelectedValue;
        myXml.TransformSource = xslFilename;
    }
}

File: RssTransform1.xsl

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/rss/channel">
  <h2 style="font: 14pt Verdana; font-weight: bold; color: #827753; background-color: #CFBD84;">
    <xsl:value-of select="title" />
  </h2>
  <p style="font: 10pt Verdana, Helvetica; margin-bottom: 10px;">
    <xsl:value-of select="description" />
  
  <xsl:for-each select="item">
    <h3 style="font: 12pt Verdana, Helvetica; border-bottom: 1px solid #A89A6C;">
      <xsl:value-of select="title" />
    </h3>
    <p style="font: 10pt Verdana, Helvetica;">
      <xsl:value-of select="description" />
      <br/>
      <a href="{link}">
        Read more
      </a>
    
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet> 

File: RssTransform2.xsl

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/rss/channel">
  <div>
    <div style="text-transform: uppercase;">
      <p style="font-size: 22px; color: #930000; margin-bottom: 2px;">
        <xsl:value-of select="title" />
      
      <p style="font-size: 11px; ">
        <xsl:value-of select="description" />
      
    </div>
    <xsl:for-each select="item">
      <div style="background-color: #D1D1D1; padding: 2px; margin-top: 8px;">
        <p style="margin-bottom: 1px; margin-top: 1px; font-size: 16px;">
          <a href="{link}" style=" color: #930000;">
          <xsl:value-of select="title" />
          </a>
        
        <p style="font-size: 10px; margin-top: 1px; margin-bottom: 1px; border-bottom: 1px dashed #949494;">
          <xsl:value-of select="pubDate" />        
        
        <p style="font: 11px Verdana, sans-serif; line-height: 18px; margin-top: 1px; margin-bottom: 1px;">
          <xsl:value-of select="description" />          
        
      </div>
    </xsl:for-each>
  </div>
</xsl:template>

</xsl:stylesheet>
9. 37. RSS
9. 37. 1. Displaying an XML RSS blog feed
9. 37. 2. Rss Reader
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.