0

我正在使用以下 RadRotator 从谷歌获取 RSS 提要:

     <telerik:RadRotator ID="RadRotator1" RotatorType="AutomaticAdvance" ScrollDirection="Up"
            ScrollDuration="2000" runat="server" DataSourceID="XmlDataSource1" Width="493"
            ItemWidth="493" Height="192" ItemHeight="75" FrameDuration="1" InitialItemIndex="-1"
            CssClass="rotator"> 

                    <%#   XPath("item") %>    



      </ItemTemplate>

发生的事情是,当我这样做时,radgrid 中没有显示任何内容

    <%#   XPath("item") %>  

请注意,我需要项目,因为它具有标题、说明等。您可以在下面的片段中看到

但如果我这样做

   <%#   XPath("description") %> 

我看到了描述,但该项目是我需要的..

以下是 google rss xml 文件的片段:

    <rss version="2.0"><channel><generator>NFE/1.0</generator><title>malaria - Google News</title><link>http://news.google.com/news?pz=1&ned=us&hl=en&q=malaria</link><language>en</language><webMaster>news-feedback@google.com</webMaster><copyright>&copy;2012 Google</copyright><pubDate>Thu, 25 Oct 2012 14:56:08 GMT</pubDate><lastBuildDate>Thu, 25 Oct 2012 14:56:08 GMT</lastBuildDate><image><title>malaria - Google News</title><url>https://ssl.gstatic.com/news/img/logo/en_us/news.gif</url><link>http://news.google.com/news?pz=1&ned=us&hl=en&q=malaria</link></image><item><title>Malaria and Acquired Immunity - AllAfrica.com</title><link>http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNHNkVuoonL7HkcwkSoAldZPsWUvNg&url=http://allafrica.com/stories/201210251151.html</link><guid isPermaLink="false">tag:news.google.com,2005:cluster=http://allafrica.com/stories/201210251151.html</guid><pubDate>Thu, 25 Oct 2012 12:16:20 GMT</pubDate><description><table border="0" cellpadding="2" cellspacing="7" style="vertical-align:top;"><tr><td width="80" align="center" valign="top"><font style="font-size:85%;font-family:arial,sans-serif"></font></td><td valign="top" class="j"><font style="font-size:85%;font-family:arial,sans-serif"><br /><div style="padding-top:0.8em;"><img alt="" height="1" width="1" /></div><div class="lh"><a href="http://news.google.com/news/url?sa=t&amp;fd=R&amp;usg=AFQjCNHNkVuoonL7HkcwkSoAldZPsWUvNg&amp;url=http://allafrica.com/stories/201210251151.html"><b><b>Malaria</b> and Acquired Immunity</b></a><br /><font size="-1"><b><font color="#6f6f6f">AllAfrica.com</font></b></font><br /><font size="-1">Even though the economic impact in Zambia has not yet been quantified, it is likely to be substantial due to the number of productive days lost due to the number of productive days lost due to <b>malaria</b>. The intensity of <b>malaria</b> in an area determines the <b>...</b></font><br /><font size="-1" class="p"></font><br /><font class="p" size="-1"><a class="p" href="http://news.google.com/news/more?ncl=dPdXW_JAl88mIRM&amp;ned=us"><nobr><b>and more&nbsp;&raquo;</b></nobr></a></font></div></font></td></tr></table></description></item>

请注意,我只是想获取它的项目部分,因为该项目是描述等的包装。

4

1 回答 1

0

这是您的方案的代码片段:

XML 数据源定义:

<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="http://news.google.com/news?pz=1&amp;cf=all&amp;ned=us&amp;hl=en&amp;q=malaria&amp;output=rss" 
                XPath="rss/channel/item"></asp:XmlDataSource>

RadRotator 定义:

        <telerik:RadRotator ID="RadRotator1" RotatorType="AutomaticAdvance" ScrollDirection="Up"
            ScrollDuration="1000"  runat="server" DataSourceID="XmlDataSource1" Width="493"
            ItemWidth="493" Height="250" ItemHeight="250" FrameDuration="2000" InitialItemIndex="-1"
            CssClass="rotator">
            <ItemTemplate>
                <div style="border: 1px solid darkgray; padding : 10px;background-color:lightgrey">
                    <a href='<%# XPath("link") %>'><%# XPath("title") %></a>
                    <div>
                        <%# XPath("description") %>
                    </div>
                </div>

            </ItemTemplate>
        </telerik:RadRotator>

到达 RSS 提要中的项目的方法是通过路径 rss/channel/item - 这将给出文档中的所有项目。然后在项目模板中,我只是抓取链接、标题和描述。项目是父节点,这就是为什么

以下是上述代码的输出:

在此处输入图像描述

于 2012-10-31T15:43:03.867 回答