Click here to Skip to main content
Click here to Skip to main content

Creating An XML Newsfeed

, 29 Jul 2002
Rate this:
Please Sign up or sign in to vote.
This article explains creating an XML newsfeed in an ASP page.

Introduction

Creating an XML newsfeed is a great way to get to grips with a real world use of XML. This tutorial, taken from CodeToad.Com will explain how to deal with the XML feeds offered by various sites on the web at the moment, and turn them into a useable web page. We will use a style sheet and a little ASP to do the job.

Click here to see how the final newsfeed page will look.

A full list of XML newsfeeds from moreover.com is available at http://w.moreover.com/categories/category_list_xml.html%20target=_blank. Amazon affiliates are also offered the chance to create their links in XML which increases the power of searches, and product placements.

We're going to use the xmlHTTP object within an ASP page to grab the XML from the URL provided by the XML-generating web site. For more information on xmlHttp see my XML HTTP Tutorial.

Once we have the XML, we call the style sheet to display the page.

Here's how the ASP page looks then :

<%

dim objHTTP , objXML , objXSL
set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objHTTP.open "GET", 
      "http://p.moreover.com/cgi-local/page?c=Pop%20music%20reviews&o=xml", 
      false
objHTTP.send
set objXML = objHTTP.responseXML
set objXSL=Server.CreateObject("microsoft.xmldom")
objXSL.async=false

objXSL.load(Server.MapPath("style.xsl"))

if (objXSL.parseError.errorCode = 0) then
    Response.Write(objXML.transformnode(objXSL))
else
    Response.Write "Error: " & objXSL.parseError.reason 
                     & "<br> URL:" & objXSL.url
end if

Set objHTTP = Nothing
Set objXML = Nothing
Set objXSL = Nothing
%>

We've referenced a style sheet called style.xsl. Our XSL style sheet loops through each item in the XML and displays the record. Obviously, you'll need to look at the XML that you have and adapt the style sheet as necessary, but this should be enough to give you an idea:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="/">

<html>
<head>
<TITLE>moreover...</TITLE>
</head>
<body BGCOLOR="ffffff">

 <br/><br/>
<br/> br

 

<DIV ALIGN="center">
<TABLE BGCOLOR="ffffff" BORDER="0" CELLPADDING="4" 
                             CELLSPACING="0" WIDTH="100%">

      <xsl:for-each select="moreovernews/article">
       
         <TR VALIGN="middle">
           <TD ALIGN="left" BGCOLOR="ffffff">
             <B>
                   <A>
             <xsl:attribute name="HREF">
               <xsl:value-of select="url"/>
             </xsl:attribute>
             <xsl:attribute name="TARGET">
               _blank
             </xsl:attribute>
             <FONT FACE="Verdana, Arial,Helvetica, 
                       sans-serif" SIZE="-1" COLOR="000000">
               <xsl:value-of select="headline_text"/>
             </FONT>
           </A>
         </B>
         <BR/>
                 <A>
           <xsl:attribute name="HREF">
             <xsl:value-of select="document_url"/>
           </xsl:attribute>
           <xsl:attribute name="TARGET">
             _blank
           </xsl:attribute>
           <FONT FACE="Verdana, Arial,Helvetica, 
                   sans-serif" SIZE="-2" COLOR="666666">
             <xsl:value-of select="source"/>
           </FONT>
         </A>
                 <A>
           <xsl:attribute name="HREF">
           <xsl:value-of select="access_registration"/>
           </xsl:attribute>
           <xsl:attribute name="TARGET">
             _blank
           </xsl:attribute>
           <FONT FACE="Verdana, Arial,Helvetica, 
                  sans-serif" SIZE="-2" COLOR="666666">
             <xsl:value-of select="access_status"/>
           </FONT>
         </A>
         <FONT FACE="Verdana, Arial,Helvetica, 
                 sans-serif" SIZE="-2" COLOR="666666">
           <xsl:value-of select="harvest_time"/> GMT
         </FONT>
           </TD>
         </TR>
          
       </xsl:for-each>


</TABLE>
</DIV>
</body>
</html>
    </xsl:template>
  </xsl:stylesheet>

Here's what the resulting page looks like. Remember we point to the original ASP page to do the work and pull in both the XML and the Style Sheet. Our newsfeed pulled in pop music news, so Click here for the latest popular music news.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

CodeToad.Com

United Kingdom United Kingdom
This script first appeared on CodeToad.Com, a developers resource of free scripts and tutorials for ASP, ASP.NET, XML, VB, DHTML, Java and other languages.

Comments and Discussions

 
QuestionWhat about web components PinsussAnonymous30-Jul-02 4:30 
AnswerRe: What about web components PinmemberCodeToad.Com30-Jul-02 5:21 
AnswerRe: What about web components PinmemberRyan Johnston30-Jul-02 11:45 
GeneralRe: What about web components PinmemberSoliant30-Jul-02 13:26 
GeneralRe: What about web components PinsussAnonymous30-Jul-02 22:15 

Fair enough.
 
It is quite optimistic to regard a software program as something that is done once, and then keeps working over the years.
Any software company is based on the opposite of this, just because they need money to live.;)
I am not saying that all software companies should do software that require maintenance. But I am afraid that's the fate of it, and that's business after all.
 
In other words, that's not because a software needs maintenance, and more particularly the config file of the software, that it is entitled to be called bad software.
 
Moreover, since the internet bubble burst, newssites change their design layout every other quarter, or even less infrequently. (For instance, codeproject didn't even change since the beginning). So what's wrong ?WTF | :WTF:
 
You also happen to miss two important points :
- "web clippers", if we name them like this, don't have to be stupid, and may adapt to changing design, layout, changing HTML code, changing CSS. That's up to the developer's smartness.
- web services burn money, and require server uptime and maintenance. At the opposite, "web clippers" are just simple software code that for instance you launch and schedule on your desktop every day in the morning. You don't need services.
 
My point in here is that newsfeed and the like deserve a much better support than the one currently in codeproject, and particularly this article which in fact does a simple XSL over an XML. What's about news ?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 30 Jul 2002
Article Copyright 2002 by CodeToad.Com
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid