ASP.NET Code
  Home arrow ASP.NET Code arrow XML News Feeds
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET CODE

XML News Feeds
By: Reno Adipura
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 15
    2002-09-04

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Thanks for your interest in the XML News Feeds. This application provides a compilation of news headlines from many sources, using the MoreOver.com's XML service. It is built on the .NET framework and uses C# as the ASP.NET server side language.

    The pages we built using Visual Studio .NET.

    Requirements:

    These files require a Web Server with the Microsoft .NET framework installed to function. To retrieve the XML news feeds, a connection to the internet from the application is necessary.

    Installation Instructions:

    Unzip the files and import them in a web, or create a new web with these files. Build the application from Visual Studio or compile using the .NET compilier. They should work as is. You can customize the look with the Style tags or simply copy past the code into your own web forms. Browse to the news.aspx page to start the application.

    Use Cases:

    News Browser: Comes to the News.aspx page and is presented with the Top Stories headlines. Using the left navigation, they can browse many topics divided into several Sections. System: The system will make a call to MoreOver.com's web site to get the XML news feed. Before each call, a check will be made to see if the headlines have been Cached. Caching occurs for each topic, and expires after a set time period, 10 minutes default.

    Adding Categories:

    To add your own categories, you will need to seek out the category name from MoreOver.com's web site, then add them to the Drop-Down list values. They can be found here: http://w.moreover.com/categories/category_list.html.

    File Descriptions:

    News.aspx: Displays the news and Navigation News.aspx.cs: Holds the Server-side processing and events fired from the Navigation drop-down boxes.

    MoreOverNews.cs: Holds the functionality to make the MoreOver.com requests and format the headlines.

    Contact:

    Please report and bugs, and we appreciate your comments or suggestions. We can be reached at webmaster@HarrisonLogic.com or visit us at www.HarrisonLogic.com.

    MoreOverNews.cs


    using System
    using System.IO
    using System.Text
    using System.Net
    using System.Xml.XPath
    namespace HL.xmlNewsFeeds 
    ///<summary />
    /// MoreOverNews.cs: This class holds methods used to retrieve 
    /// MoreOver XML 
    /// news feeds from their site. You will have to know the 
    /// Catagory to use in 
    /// the MoreOver uri. We have compiled several for you to use,
    /// however you can 
    /// find others by visiting their site. - HarrisonLogic 
    ///</summary />
    public class MoreOverNews 
    public static 
    string GetNews(string Category
    int NoReturnedArticles
    string articlePrefixstring articleSuffix) { 
    /* PARAMETERS: Category: MoreOver.com's Topic category, 
       find legal Categories from their site 
       NoReturnedArticles: Number of article links you would 
       like retrieved 
       articlePrefix: Code inserted in from of each article link. 
       (i.e. </p>, <li>,<td />..etc) 
       articleSuffix: Code inserted at the end of each article link. */ 
    if (NoReturnedArticles 25 NoReturnedArticles <1) { 
    // Default to 5 Headlines if not within range 
    NoReturnedArticles 5; } 
    // Use this news Uri from MoreOver.com 
    string newsUri "http://p.moreover.com/cgi-local/page?c=" 
    Category.Trim() + "&o=xml"
    // Use the String builder object, more efficient than a string 
    StringBuilder newsContent = new StringBuilder(1024); 
    // Keep track of number of Articles 
    int articleCount 0
    // Use the WebRequest / Response objects, allows us to set a timeout 
    WebRequest moReq
    WebResponse moRes
    Stream moStream
    // Set timeout for five seconds 
    moReq WebRequest.Create(newsUri); 
    moReq.Timeout 5000
    // Get the Response and insert in the Stream object 
    moRes moReq.GetResponse(); 
    moStream moRes.GetResponseStream(); 
    //Open a XPathDocument with Stream Object 
    XPathDocument doc=new XPathDocument(moStream); 
    //Create the XPath navigator 
    XPathNavigator nav=((IXPathNavigable)doc).CreateNavigator(); 
    //create the XPathNodeIterator of Article nodes 
    XPathNodeIterator iter=nav.Select("/moreovernews/article"); 
    while(
    iter.MoveNext() & articleCount != NoReturnedArticles) { 
    newsContent.Append(articlePrefix LoadArticle(iter.Current
    articleSuffix); articleCount += 1; } 
    // Do a simple check to see if there are no articles returned, 
    //this could be 
    // the result of a bad Cateogry name 
    if (articleCount == 0) { 
    newsContent.Append("There were no articles returned for your category.


    If you feel there should be articles returned, contact the system 
    administrator."
    ); } 
    return 
    newsContent.ToString(); } 
    private static 
    string LoadArticle(XPathNavigator lstNav) { 
    string headline ""
    string url ""
    string source ""
    // We are passsed an XPathNavigator of a particular Article node 
    // we will select all of the direct descendents and return the 
    //article link 
    XPathNodeIterator 
     iterArticle
    =lstNav.SelectDescendants(XPathNodeType.Element,false); 
    while(
    iterArticle.MoveNext()) { 
    switch(
    iterArticle.Current.Name) { 
    case 
    "headline_text"headline iterArticle.Current.Value
    break; 
    case 
    "url"url iterArticle.Current.Value
    break; 
    case 
    "source"source iterArticle.Current.Value; break; } 

    //return article link; 
    return "<a class="newslink" href="" target="_blank">" headline 
    "</a>" " <i>" source "</i>"


    }

    News.aspx

    <!--aspPage language="c#" Codebehind="News.aspx.cs" 
    AutoEventWireup="false" Inherits="HL.xmlNewsFeeds.News" -->
    <
    meta content="C#" name="CODE_LANGUAGE" />
    <
    meta content="JavaScript" name="vs_defaultClientScript" />
    <
    meta content="http://schemas.microsoft.com/intellisense/ie5" 
    name="vs_targetSchema" />
    <
    style>.headingCell {BACKGROUND-COLOR#006699; color: white; 
    font-stylesmall-caps }
                .
    navigationCell {BACKGROUND-COLOR#FFFFCC;}
                
    .newsDropDown {FONT-SIZE8ptWIDTH100px
                
    FONT-FAMILYtahomaBACKGROUND-COLOR#eeeeee; }
                
    td font-size10ptfont-family"Trebuchet MS"
                }</
    style>
    <
    form id="News" method="post" runat="server">
    <
    table cellspacing="0" cellpadding="5" width="98%" border="0">
    <
    tbody>
    <
    tr>
    <
    td class="navigationCell" valign="top">
    <
    p>
    <
    table cellspacing="0" cellpadding="2" width="150" border="0">
    <
    tbody>
    <
    tr>
    <
    td class="headingCell">   Browse News</td></tr>
    </
    tr />
    <
    tr>
    <
    td>  Top Headlines

    <dropdownlist id="TopHeadlines" runat="server" autopostback="True" 
    cssclass="newsDropDown" onselectedindexchanged="LoadTopNews" />
    <
    listitem /> 
    </
    listitem />
    <
    listitem value="Top%20business%20stories" />Business
    <listitem value="Top%20stories" />Top Stories
    </listitem />
    <
    listitem value="Top%20internet%20stories" />Internet
    </listitem />
    <
    listitem value="Top%20US%20stories" />US news
    </listitem />
    <
    listitem value="Sports%3A%20top%20stories" />Sports
    </listitem />
    <
    listitem value="International%20relations%20news" />International
    </listitem />
    <
    p>Technology

    <dropdownlist id="Technology" runat="server" autopostback="True" 
    cssclass="newsDropDown" onselectedindexchanged="LoadTechNews" />
    <
    listitem /> 
    </
    listitem />
    <
    listitem value="Developer%20news" />Web Developer
    <listitem value="Webmaster%20tips" />Web Master
    </listitem />
    <
    listitem value="Java%20news" />Java
    </listitem />
    <
    listitem value="Wireless%20sector%20news" />Wireless
    </listitem /></p>
    <
    p> </p>
    <
    p>Financial

    <dropdownlist id="Finance" runat="server" autopostback="True" 
    cssclass="newsDropDown" onselectedindexchanged="LoadFinanceNews" />
    <
    listitem /> 
    </
    listitem />
    <
    listitem value="Personal%20finance%20news" />Personal Finance
    <listitem value="Mutual%20funds%20news" />Mutual Funds
    </listitem />
    <
    listitem value="Stock%20Exchanges%20news" />Stock Exchange
    </listitem /></p>
    <
    p> </p>
    <
    p>Sports

    <dropdownlist id="Sports" runat="server" autopostback="True" 
    cssclass="newsDropDown" onselectedindexchanged="LoadSportsNews" />
    <
    listitem /> 
    </
    listitem />
    <
    listitem value="Sports%3A%20baseball%20news" />Baseball
    <listitem value="Sports%3A%20basketball%20news" />Basketball
    </listitem />
    <
    listitem value="Sports%3A%20boxing%20news" />Boxing
    </listitem />
    <
    listitem value="Sports%3A%20American%20football%20news" />Football
    </listitem /></p>
    <
    p> </p>
    <
    p>Special Interest

    <dropdownlist id="Interest" runat="server" autopostback="True" 
    cssclass="newsDropDown" onselectedindexchanged="LoadInterestNews" />
    <
    listitem /> 
    </
    listitem />
    <
    listitem value="Consumer%3A%20fitness%20news" />Fitness
    <listitem value="Religion%20news" />Religion
    </listitem />
    <
    listitem value="Science%20news" />Science
    </listitem />
    <
    listitem value="Space%20science%20news" />Space
    </listitem />
    <
    listitem value="Consumer%3A%20parenting%20news" />Parenting
    </listitem /></p>
    <
    p> </p></td>
    <
    td valign="top" width="100%"><b><label id="Heading" runat="server">
     </
    label></b>
    <
    p> </p><label id="headlines" runat="server"> </label></td>

    News.aspx.cs

    using System
    using System.Collections
    using System.ComponentModel
    using System.Data
    using System.Drawing
    using System.Web
    using System.Web.SessionState
    using System.Web.UI
    using System.Web.UI.WebControls
    using System.Web.UI.HtmlControls
    namespace HL.xmlNewsFeeds 
    ///<summary />
    /// This page uses the Classes in MoreOverNews.cs to pull news
    /// feed from 
    /// the site MoreOver.com, which generates XML news 
    ///feed comiliations. 
    /// 
    /// I have defaulted to Top Stories when first reaching the page,
    /// and if 
    /// there is a blank selection. You may change at will. 
    /// 
    /// More downloadable applications are available at 
    ///ww.HarrisonLogic.com 
    /// Thanks for your interest. 
    ///</summary />
    public class News System.Web.UI.Page 
    protected 
    System.Web.UI.WebControls.DropDownList TopHeadlines
    protected 
    System.Web.UI.WebControls.DropDownList Technology
    protected 
    System.Web.UI.WebControls.DropDownList Interest
    protected 
    System.Web.UI.WebControls.Label Heading
    protected 
    System.Web.UI.WebControls.DropDownList Finance
    protected 
    System.Web.UI.WebControls.DropDownList Sports
    protected 
    System.Web.UI.WebControls.Label headlines
    private 
    void Page_Load(object senderSystem.EventArgs e) { 
    if (!
    this.IsPostBack) { 
    // Default to Top Stories 
    Heading.Text "Top Stories"
    headlines.Text GetNewsFeed("Top%20stories"); } 

    private 
    string GetNewsFeed(string Category) { 
    string newsArticles ""
    // We want to check for the cache first 
    if (Cache[Category] == null) { 
    try { 
    // Get the news from MoreOver using the 
    // Methods in MoreOverNews.cs 
    string MoreOverArticles ""
    MoreOverArticles 
    HL.xmlNewsFeeds.MoreOverNews.GetNews(Category10
    "<li>""<p>"); 
    // Cache for 10 minutes, see the 'Cache' documentation 
    //for more info 
    //on this method 
    Cache.Insert(CategoryMoreOverArticlesnull
    System.Web.Caching.Cache.NoAbsoluteExpiration
    TimeSpan.FromMinutes(10)); 
    newsArticles MoreOverArticles; } 
    catch (
    Exception err) { 
    // Catch any errors and report to the user 
    newsArticles "<i>Error: No news headlines were retrieved.</i> </p>
    <p><font size="
    -1">" err.Message " </font></p>"; } 

    else { 
    // Use the Cached information 
    newsArticles Cache[Category].ToString(); } 
    return 
    newsArticles; } 
    public 
    void LoadTopNews(object senderSystem.EventArgs e) { 
    if (
    TopHeadlines.SelectedItem.ToString().Trim() == "") { 
    Heading.Text "Top Stories"
    headlines.Text GetNewsFeed("Top%20stories"); } 
    else { 
    Heading.Text TopHeadlines.SelectedItem.ToString().Trim(); 
    headlines.Text 
    GetNewsFeed(TopHeadlines.SelectedItem.Value.ToString().Trim()
    ); } 

    public 
    void LoadFinanceNews(object senderSystem.EventArgs e) { 
    if (
    Finance.SelectedItem.ToString().Trim() == "") { 
    Heading.Text "Top Stories"
    headlines.Text GetNewsFeed("Top%20stories"); } 
    else { 
    Heading.Text Finance.SelectedItem.ToString().Trim(); 
    headlines.Text 
    GetNewsFeed(Finance.SelectedItem.Value.ToString().Trim()
    ); } 

    public 
    void LoadSportsNews(object senderSystem.EventArgs e) { 
    if (
    Sports.SelectedItem.ToString().Trim() == "") { 
    Heading.Text "Top Stories"
    headlines.Text GetNewsFeed("Top%20stories"); } 
    else { 
    Heading.Text Sports.SelectedItem.ToString().Trim(); 
    headlines.Text 
    GetNewsFeed(Sports.SelectedItem.Value.ToString().Trim()
    ); } 

    public 
    void LoadTechNews(object senderSystem.EventArgs e) { 
    if (
    Technology.SelectedItem.ToString().Trim() == "") { 
    Heading.Text "Top Stories"
    headlines.Text GetNewsFeed("Top%20stories"); } 
    else { 
    Heading.Text Technology.SelectedItem.ToString().Trim(); 
    headlines.Text 
    GetNewsFeed(Technology.SelectedItem.Value.ToString().Trim()
    ); } 

    public 
    void 
    LoadInterestNews
    (object senderSystem.EventArgs e) { 
    if (
    Interest.SelectedItem.ToString().Trim() == "") { 
    Heading.Text "Top Stories"
    headlines.Text GetNewsFeed("Top%20stories"); } 
    else { 
    Heading.Text Interest.SelectedItem.ToString().Trim(); 
    headlines.Text 
    GetNewsFeed(Interest.SelectedItem.Value.ToString().Trim()
    ); } 

    #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); } 
    ///<summary />
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    ///</summary />
    private void InitializeComponent() { 
    this.Load += new System.EventHandler(this.Page_Load); } 
    #endregion } 

     

     


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP.NET Code Articles
    More By Reno Adipura

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Did you say mainframe? e-kit

    Learn how you can extend modern application lifecycle management to IBM System z through the IBM Rational Software Delivery Platform (SDP). The Did you say mainframe? e-kit includes podcasts, webcasts, tutorials, white and red papers, demos, and articles designed to help ease the challenges of modernizing your enterprise. This complimentary kit for mainframe developers is a practical, how-to guide for making the most of an existing development environment, including the skills and infrastructure already in place at an established enterprise.
    FREE! Go There Now!


    NEW! Download DB2 9.5 for Linux, Unix, and Windows

    Download a free trial version of IBM DB2 9.5 for Linux, UNIX, and Windows. DB2 9 is the result of a five-year development project that transformed traditional (static) database technology into an interactive data server that merges the high performance and ease of use of DB2 with the self-describing benefits of XML.
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 2: Automate builds for a real-world Tomcat project

    Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available.
    FREE! Go There Now!


    NEW! Integrating XML into Your Enterprise Using Data Federation

    XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats.
    FREE! Go There Now!


    NEW! Rational Modeling Extension for Microsoft.Net

    Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Tester for SOA Quality V7.0.1

    Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services.
    FREE! Go There Now!


    NEW! Using IBM Rational Developer for System z and IBM Rational ClearCase together to manage application development

    Whether you are creating new applications or modifying existing ones, managing integration of new components with traditional z/OS elements is a critical part of building and deploying modern applications. Listen to this webcast to see how IBM can help you optimize your development process using an IDE like Rational Developer for System z that integrates with management tools, such as ClearCase to manage your application development on mainframes.
    FREE! Go There Now!


    NEW! Using Rational Business Developer to enhance your developer productivity

    Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components.
    FREE! Go There Now!


    NEW! Webcast: Quickly provide customized, integrated user interfaces with Lotus Notes 8

    IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community.
    FREE! Go There Now!


    NEW! Webcast: Striking the right balance between manual and automated testing

    Join this webcast to learn how IBM Rational's Functional Testing solution enables you to implement automation your way, at your pace, with your existing staff. In this webcast, you’ll learn how you can eliminate redundancy of manual test scripts, reduce errors, and increase test coverage through test automation. After this presentation you will understand how IBM Rational Functional Testing solution can streamline your manual testing and make test automation easily attainable.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP.NET CODE ARTICLES

    - How to Use the ListBox Control in ASP.NET 2.0
    - How to Load XML Documents in ASP.NET 2.0
    - DataGrid Code
    - ASP.NET Guestbook
    - User Controls and Client Side Scripting
    - ASP.NET Programming with Microsoft's AS...
    - ASP.NET Basics (part 3): Hard Choices
    - ASP.NET Basics (part 2): Not My Type
    - ASP.NET Basics (part 1): Nothing But .Net
    - Directory Tree Browser
    - How to get the confirmation of Yes/No from a...
    - Complete example using custom errors and wri...
    - Paging Certain # records per page .NET style
    - General Methods of formatting and Subtractin...
    - .NET LinkButton web control





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT