Share via


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="https://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="https://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="html"/>

<xsl:template match="/">

<HTML>

<body>

<title>

<xsl:value-of select="//rss/channel/title"/>

</title>

<xsl:for-each select="//rss/channel/item">

<font color="#ff00ff" size="4">

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

</font>

<p><xsl:value-of select="pubDate"/></p>

<p>

<xsl:value-of select="description"/>

</p>

<br/>

</xsl:for-each>

</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

  • Anonymous
    January 11, 2005
    Or, just use Opera/Firefox/Maxthon/Deepnet/whatever?

  • Anonymous
    August 05, 2005
    Sometimes I need to test something using VBScript. A user sends a code snippet and asks why it behaves...

  • Anonymous
    May 25, 2006
    Today’s sample shows how to create a web crawler in the background. This crawler starts with a web page,...

  • Anonymous
    May 11, 2007
    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]

  • Anonymous
    October 04, 2007
    There's a very useful feature that FoxPro users have had for over 2 decades: being able to output text

  • Anonymous
    October 04, 2007
    There&#39;s a very useful feature that FoxPro users have had for over 2 decades: being able to output

  • Anonymous
    December 06, 2007
    PingBack from http://msdnrss.thecoderblogs.com/2007/12/06/how-to-create-dynamic-xaml-to-display-arbitrary-xml/

  • Anonymous
    June 09, 2008
    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" 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.