====== [Edit1] ======
跟进问题:
使用下面提供的答案,通过FloatingKiwi,我希望能够解析并找到第一个"附件"标记在每个"项目"
中目前,我能够想出这个:
Dim xml_items = From ImageURL In xelement.<channel>.<item>
Dim url = xml_items.<enclosure>.@url
For Each item As XElement In xml_items
TextBox1.Text = TextBox1.Text + Environment.NewLine + Environment.NewLine + url
Next item
这似乎给了我第一个&#34;圈地&#34;标记为第一个&#34;项目&#34; 15次(xml中的项目数)
总是赞赏任何帮助:)
=============================================== ============
我一直想尝试解决这个问题,但我无法找到如何从RSS Feed中提取图片的网址。
我想解析整个RSS Feed来提取图片网址,这是一个封装标签,但我似乎无法获得它。
以下是我到目前为止的代码。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xelement As XElement = XElement.Load("..\\..\\example.xml")
Dim links As IEnumerable(Of XElement) = xelement.Elements()
Dim url = From ImageURL In xelement.Elements("item") Where CStr(ImageURL.Element("enclosure").Attribute("url")) Select ImageURL
For Each link As XElement In url
TextBox1.Text = TextBox1.Text + Environment.NewLine + Environment.NewLine + link.Element("item").Value
Next link
End Sub
以下是xML内容的示例:
<rss version="2.0">
<channel>
<title>Beverly Hills Car Club RSS 2.0 Feed</title>
<link>http://www.beverlyhillscarclub.com/</link>
<description>Beverly Hills Car Club RSS 2.0 Feed</description>
<language>en-us</language>
<item>
<title>1969 Alfa Romeo Duetto</title>
<description>
<=!=[=C=D=A=T=A=[
1969 Alfa Romeo Duetto <br /> Stock # 03077, Mileage: 0, VIN # <br /> Price: $17,500<br /> Exterior Color: Silver, Interior Color: <br /> <div style="text-align: center;"><span style="color: rgb(255, 0, 0);"><span style="font-size: xx-large;"><em><strong> <span style="font-family: A
]=]=>
<=!=[=C=D=A=T=A=[
rial, Helvetica, sans-serif;">1969 Alfa Romeo Duetto with 2 Tops</span></strong></em></span></span></div><br style="font-family: Arial, Helvetica, sans-serif;" /><span style="font-size: large;"><span style="font-family: Arial, Helvetica, sans-serif;">1969 Alfa Romeo Duetto, 2 tops, silver with red interior, beautiful color combination, covered headlights, very clean and detailed engine bay, solid undercarriage, nice weekend driver that is mechanically sound. For $17,500</span><br style="font-family: Arial, Helvetica, sans-serif;" /><br style="font-family: Arial, Helvetica, sans-serif;" /><span style="font-family: Arial, Helvetica, sans-serif;">If you have any additional questions <strong><span style="color: rgb(0, 255, 0);">Please call 310-975-0272</span></strong> or email with any questions! We also welcome all international buyers. We can help with shipping quotes and arrangements.</span></span>
]=]=>
</description>
<link>
1969 Alfa Romeo Duetto
</link>
<enclosure url="http://www.beverlyhillscarclub.com/galleria_images/2078/2078_main_t.jpg" length="2791" type="image/jpeg"/> <----------------- this is what I need ------------------>
<guid>
1969 Alfa Romeo Duetto
</guid>
<pubDate>Wed, 16 Oct 2013 03:25:21 CDT</pubDate>
非常感谢任何帮助。
答案 0 :(得分:1)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xelement As XElement = XElement.Load("..\\..\\example.xml")
For Each item In xelement.<channel>.<item>
Dim url = item.<enclosure>.@url
TextBox1.Text = TextBox1.Text + Environment.NewLine + Environment.NewLine + url
Next
End Sub
答案 1 :(得分:1)
这里的问题是你在循环开始之前设置了url,所以它始终指向第一个项目。在循环内移动url的赋值并将其指向item而不是xml_items
Dim xml_items = From ImageURL In XElement.<channel>.<item>
For Each item As XElement In xml_items
Dim url = item.<enclosure>.@url
TextBox1.Text = TextBox1.Text + Environment.NewLine + Environment.NewLine + url
Next item