Use a simple XSLT to read the RSS feed from a blog


On most Blogs, there is a link called “Syndication”,”RSS”, or “XML” that is the RSS feed. Click on that, and you see an XML document that contains some recent blog posts.

 

This simple code reads the RSS feed for my blog, does an XSLT transform of the XML to a simple HTML file, and opens the HTML in IE

 

Just start VFP, choose File->New->Program, paste in this code, then hit Ctrl-E to run it.

 

cUrl=”http://blogs.msdn.com/calvin_hsia/Rss.aspx”

oHTTP=CREATEOBJECT(“winhttp.winhttprequest.5”)

oHTTP.Open(“POST”,cUrl,.f.)

oHTTP.Send()

*ohttp.SetTimeouts( && use this for setting the timeouts

 

TEXT TO cXSLT noshow

<?xml version=”1.0″?>

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

<xsl:output method=”html”/>

<xsl:template match=”/”>

<HTML>

<body>

<title>

<xsl:valueof select=”//rss/channel/title”/>

</title>

<xsl:foreach select=”//rss/channel/item”>

<font color=”#ff00ff” size=”4″>

&lt;a href=”<xsl:value-of select=”link“/>”&gt;<xsl:valueof select=”title”/>&lt;/a&gt;

</font>

<p><xsl:valueof select=”pubDate”/></p>

<p>

<xsl:valueof select=”description”/>

</p>

<br/>

</xsl:foreach>

 

</body>

</HTML>

</xsl:template>

</xsl:stylesheet>

ENDTEXT

 

oXML=CREATEOBJECT(“msxml.domdocument”)

oXML.loadXML(oHTTP.ResponseText)

oXSLT=CREATEOBJECT(“msxml.domdocument”)

oXSLT.loadXML(cXSLT)

cTrans=oxml.transformNode(oxslt)    && do the XSLT transform

cTrans=STRTRAN(cTrans,”&amp;”,”&”)  && convert “&amp;” to “&”

cTrans=STRTRAN(cTrans,”&gt;”,”>”)

cTrans=STRTRAN(cTrans,”&lt;”,”<“)

 

STRTOFILE(cTrans,”c:\t.htm”)        && output to a tempfile

oie=CREATEOBJECT(“internetexplorer.application”)

oie.visible=1

oie.navigate(“c:\t.htm”)

 

 

My next post will show how to retrieve all posts from a particular blog.

 

47844

 

Comments (13)

  1. Mr Blobby says:

    Or, just use Opera/Firefox/Maxthon/Deepnet/whatever?

  2. .Net Adventures says:
  3. Sometimes I need to test something using VBScript. A user sends a code snippet and asks why it behaves…

  4. Today’s sample shows how to create a web crawler in the background. This crawler starts with a web page,…

  5. pwisg says:

    http://Booksa.vdforum.ru <a href= http://Booksa.vdforum.ru >Out of print books</a> [url=http://Booksa.vdforum.ru]Out of print books[/url]

  6. There’s a very useful feature that FoxPro users have had for over 2 decades: being able to output text

  7. There&#39;s a very useful feature that FoxPro users have had for over 2 decades: being able to output

  8. YBENAM says:

    THIS IS A QUESTION -PLEASE ANSWER ME AT MY URL

    I HAVE VFP6.0 FIRST EDITION AND I MEET A PROBLEM USING

    HERE IS MY PROGRAM:

    *********************************************

    URL = "http://www.atoutfox.org/images/foxpro.jpg&quot;

    xml = CreateObject("Microsoft.XMLHTTP")

    xml.Open("GET", URL, .f.)

    xml.Send

    messagebox(vartype(xml.responseBody))   &&return Numeric !

    *******

    oStream = createobject("Adodb.Stream")

    *#define  adTypeBinary  1

    *#define adSaveCreateOverWrite  2

    *#define adSaveCreateNotExist  1

    oStream.type =1      && adTypeBinary

    oStream.open

    *******************************************

    oStream.write(xml.responseBody)   && Return error here

    *=strtofile(xml.responseBody,imagefile)  &&return also error

    ******************************************

    *’ Do not overwrite an existing file

    oStream.savetofile(ImageFile,1)      && 1 adSaveCreateNotExist  2  adSaveCreateOverWrite

    oStream.close

    oStream = null

    xml =null

    ********************************

    is here a difference between vfp6 and laters versions ? why vfp6.0 return error ?

    thank you.