【问题标题】:How i can display the output of a rss feed in HTML format in a TWebBrowser?如何在 TWebBrowser 中以 HTML 格式显示 rss 提要的输出?
【发布时间】:2012-04-07 20:37:02
【问题描述】:

我想在 TWebBrowser 组件中以格式化 HTML 格式显示 rss 提要的输出,如果在 TWeb 浏览器中加载此提要 http://code.google.com/feeds/p/v8/svnchanges/basic,这会将内容显示为 XML 文件

但是如果我用IE加载同一个页面

我尝试按照这个问题CSS and TWebbrowser delphi 中的建议将 css 注入到加载的 IHTMLDocument2 中,但我仍然得到相同的结果。

问题是,我如何在 TWebbrowser 中加载 rss 提要,但像 IE 一样将输出显示为 HTML 文档?

【问题讨论】:

    标签: html css delphi delphi-xe2 twebbrowser


    【解决方案1】:

    只是一个猜测,但您可以尝试应用以下 XSL 样式表(取自 http://snippets.dzone.com/posts/show/1162,并按照下面 cmets 中 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>
    

    到您收到的提要。要转换文档,请参考this question's selected answer,然后您可以尝试将生成的 XML 分配给 WebBrowser。

    我猜您将 WebBrowser 控件指向提要,但使用这种方法,您需要使用例如 Indy 下载提要(查看 TIdHTTP 及其 Get() 方法),转换它,然后显示在您的控件中。

    请注意,以上只是一个猜测,但我相信这是一个很好的假设。 :)

    【讨论】:

      【解决方案2】:

      IE 正在将默认样式表和 XSL 转换应用于 RSS 提要 XML。这是 IE 的东西,而不是标准或类似的东西。

      您需要自己做类似的事情,在页面显示之前对其进行修改。

      【讨论】:

        猜你喜欢
        • 2015-12-01
        • 1970-01-01
        • 2011-07-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多