【问题标题】:Error on retrieving RSS Feed (vb.net project)检索 RSS 提要时出错(vb.net 项目)
【发布时间】:2013-05-17 12:50:34
【问题描述】:

所以,我正在 vb.net 上开发一个项目来管理 rss 提要,如果它们附有文件,它会自动将文件下载到文件夹中。我对 vb.net 有所了解,但在 Xml 中我迈出了第一步。

我已经设法从网上找到的带有此代码的链接中正确下载内容:

Dim webReq As HttpWebRequest = DirectCast(WebRequest.Create(tsCboFeeds.Text), HttpWebRequest)

webReq.AutomaticDecompression = DecompressionMethods.GZip

Dim resp As HttpWebResponse = DirectCast(webReq.GetResponse(), HttpWebResponse)
Dim xml As String
Using sr As New StreamReader(resp.GetResponseStream())
   xml = sr.ReadToEnd()
End Using

doc.LoadXml(xml)

它适用于我发现的 99% 的提要,唯一的问题是那些在附件标签中包含下载 url 的提要,例如这个示例(链接是帖子的 url,而不是文件的链接) :

<channel>
<title>...</title>
<link>...</link>
<description>...</description>

<item>
    <title>...</title>
    <description>...</description>
    <category>...</category>
    <author>...</author> 
    <link...</link>
    <pubDate>...</pubDate>
    <enclosure url="http:..." />
</item>

当我尝试使用时

Dim nodesLink As XPathNodeIterator = navigator.Select("/rss/channel/item/enclosure_url")

我没有得到标签内的信息,它给了我整个 xml 文档。

正如我所提到的,我不太了解 Xml,但现在我尝试了一些我在网上找到的解决方案,甚至更改了获取文件的方法,但主要是因为存在问题,这种方法对我来说是最好的项目。

有什么想法吗?

【问题讨论】:

    标签: vb.net rss feed


    【解决方案1】:

    我认为问题在于您的 xpath 表达式是错误的。在 Xml 中,我看到一个名为的元素,而不是一个名为 .

    你可以试试这个:

    Dim nodesLink As XPathNodeIterator = navigator.Select("/rss/channel/item/enclosure")
    nodesLink.Attributes("url")
    

    【讨论】:

    • 嗨。感谢您的回复我尝试编写nodesLink.attributes,但我的项目无法识别该属性。我已经有大量的进口商品,但也许我缺少一个。我已经导入的是: Imports System.Collections.Specialized Imports System.Collections Imports System.Linq Imports System.Web Imports System.Xml Imports System Imports System.Net Imports System.Xml.XPath Imports System.IO Imports System.Text
    • 我对 XPathNodeIterator 和 XmlDocument 感到困惑,对此感到抱歉。我认为您应该使用此代码(未测试):Dim xp As XPathNavigator = nodesLink.Currentxp.GetAttribute("url",Nothing)
    • 再次感谢您的帮助。虽然没有帮助:/我猜RSS太破了,无法阅读。还是谢谢
    猜你喜欢
    • 1970-01-01
    • 2013-04-13
    • 1970-01-01
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-18
    • 1970-01-01
    相关资源
    最近更新 更多