Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can display the output of a rss feed in HTML format in a TWebBrowser?

I Want to show the output of a rss feed in a formatted HTML in a TWebBrowser component, if a load this feed http://code.google.com/feeds/p/v8/svnchanges/basic in a TWebbrowser, this shows the content as a XML file

enter image description here

but if I use IE to load the same page

enter image description here

I tried injecting a css to the loaded IHTMLDocument2 as is suggested in this question CSS and TWebbrowser delphi but i still getting the same result.

The question is, how i can load the rss feed in TWebbrowser but showing the output as HTML document like IE does?

like image 664
Salvador Avatar asked Apr 07 '12 20:04

Salvador


2 Answers

Just a guess, but you might try applying the following XSL stylesheet (taken from http://snippets.dzone.com/posts/show/1162 and modified as suggested by cherdt in the comments below):

<xsl:stylesheet version="1.0"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dc="http://purl.org/dc/elements/1.1/">
    <xsl:output method="html"/>
    <xsl:template match="/">
    <xsl:apply-templates select="/atom:feed/atom:head"/>
        <xsl:apply-templates select="/atom:feed"/>
    </xsl:template>
    <xsl:template match="atom:feed/atom:head">
        <h3><xsl:value-of select="atom:title"/></h3>
        <xsl:if test="atom:tagline"><p><xsl:value-of select="atom:tagline"/></p></xsl:if>
        <xsl:if test="atom:subtitle"><p><xsl:value-of select="atom:subtitle"/></p></xsl:if>
    </xsl:template>
    <xsl:template match="/atom:feed">
        <h3><xsl:value-of select="atom:title"/></h3>
        <xsl:if test="atom:tagline"><p><xsl:value-of select="atom:tagline"/></p></xsl:if>
        <xsl:if test="atom:subtitle"><p><xsl:value-of select="atom:subtitle"/></p></xsl:if>
        <ul>
            <xsl:apply-templates select="atom:entry"/>
        </ul>
    </xsl:template>
    <xsl:template match="atom:entry">
        <li>
            <a href="{atom:link[@rel='related']/@href}" title="{substring(atom:published, 0, 11)}"><xsl:value-of select="atom:title"/></a>
            <xsl:choose>
                <xsl:when test="atom:content != ''">
                    <p><xsl:value-of select="atom:content" disable-output-escaping="yes" /></p>
                </xsl:when>
                <xsl:otherwise>
                    <p><xsl:value-of select="atom:summary" disable-output-escaping="yes" /></p>
                </xsl:otherwise>
            </xsl:choose>
        </li>
    </xsl:template>
</xsl:stylesheet>

To the feed you are receiving. To transform the document, refer to this question's selected answer and then you could try to assign the resulting XML to the WebBrowser.

I am guessing that you are pointing your WebBrowser control to the feed, but using this approach you would need to download the feed using, for example, Indy (check out TIdHTTP and its Get() method), transform it, and then display in your control.

Please note that the above is just a guess, but I believe it is a good assumption. :)

like image 50
Pateman Avatar answered Nov 07 '22 13:11

Pateman


IE is applying a default style sheet and XSL transform to the RSS feed XML. This is an IE thing rather than a standard or anything like that.

You would need to do something similar yourself by modifying the page before it is displayed.

like image 2
Toby Allen Avatar answered Nov 07 '22 14:11

Toby Allen