I want to get each items from xml feed link I specify. Here is the XML format,
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<title>Site title</title>
<link>http://www.blahblah.com</link>
<language>ru</language>
<description>This site rocks</description>
<generator>DataLife Engine</generator>
<item>
<title>Item no 1 title</title>
<guid isPermaLink="true">http://www.blahblah.com/item1</guid>
<link>http://www.blahblah.com/item1</link>
<description>Description of item 1</description>
<category>Category 0</category>
<dc:creator>admin</dc:creator>
<pubDate>Fri, 19 Sep 2014 08:00:00 +0000</pubDate>
</item>
<item>
<title>Item no 2 title</title>
<guid isPermaLink="true">http://www.blahblah.com/item2</guid>
<link>http://www.blahblah.com/item2</link>
<description>Description of item 2</description>
<category>Category 0</category>
<dc:creator>admin</dc:creator>
<pubDate>Fri, 19 Sep 2014 07:00:00 +0000</pubDate>
</item>
</channel>
</rss>
Here is a sample item in a feed. For each <item></item>
there, it has its own title, description and link to the page.
I want the title to be kept in TextBox 1, link in TextBox 2, and description in TextBox 3 for the first item only.
Mostly, I want them to be saved as a string so I can continue with my code using those strings.
Can anyone help me with this?
I have tried something like this:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
File.Delete(paths)
If Not File.Exists(paths) Then
File.Create(paths).Dispose()
End If
Dim Lines() As String
Dim stringSeparators() As String = {vbCrLf}
Dim Source As String
Dim wc As New WebClient
Source = wc.DownloadString("http://blahblah.com/rss.xml")
File.WriteAllText(paths, Source)
xDoc.Load(paths)
Dim manager As XmlNamespaceManager = New XmlNamespaceManager(xDoc.NameTable)
manager.AddNamespace("atom", "http://www.w3.org/2005/Atom")
Dim xnList As XmlNodeList = xDoc.SelectNodes("atom:feed/atom:entry", manager)
For Each xn As XmlNode In xnList
TextBox1.Text = xn.LocalName.ToString() + vbCrLf
Next
End Sub
This way, I have managed to download the whole file and save it as string. But I am not really able to get done with the last part. I don't understand how xml file works, so I think the mistake here is near the atom part.
What I wanted was to read a XML file, then save each item
, TITLE
, LINK
and DESCRIPTION
in a text file.
like, TITLE:LINK:DESCRIPTION
one in each line for one item. My example RSS above can make 2 lines.