我想在TWebBrowser组件中以格式化的HTML显示rss feed的输出,如果在TWebbrowser中加载此Feed http://code.google.com/feeds/p/v8/svnchanges/basic,则会将内容显示为XML文件
但如果我使用IE加载同一页面
我尝试将css注入已加载的IHTMLDocument2,如此问题CSS and TWebbrowser delphi中所述,但我仍然得到相同的结果。
问题是,如何在TWebbrowser中加载rss feed但是将输出显示为像IE这样的HTML文档呢?
答案 0 :(得分:5)
只是一个猜测,但您可以尝试应用以下XSL样式表(取自http://snippets.dzone.com/posts/show/1162并按照以下评论中的cherdt的建议进行修改):
<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>
到您收到的Feed。要转换文档,请参阅this question's selected answer,然后您可以尝试将生成的XML分配给WebBrowser。
我猜你正在将你的WebBrowser控件指向feed,但是使用这种方法你需要使用例如Indy下载feed(查看TIdHTTP
及其Get()
方法),转换它,然后在你的控件中显示。
请注意,以上只是一个猜测,但我相信这是一个很好的假设。 :)
答案 1 :(得分:2)
IE正在将默认样式表和XSL转换应用于RSS提要XML。这是一个IE的东西,而不是标准或类似的东西。
您需要通过在页面显示之前修改页面来自己做类似的事情。