Rss Feed

mkvidyashankar

Active Member
Licensed User
Longtime User
Hi

I am trying to read RSS feed from bbc news website, my code is like this


Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
Dim heading,linkrs,descr As String

If Parser.Parents.IndexOf("item") > -1 Then

If Name="title" Then heading=Text
Else If Name="description" Then descr=Text

End If
If heading.Length > 0 Then listrss.AddTwoLines(heading,descr)
End Sub

RSS feed is like this

<item>
<title>Galleon founder Rajaratnam guilty</title>
<description>US hedge fund billionaire Raj Rajaratnam is found guilty of making tens of millions of dollars from insider trading.</description>
<link>http://www.bbc.co.uk/go/rss/int/news/-/news/business-13188529</link>
<guid isPermaLink="false">http://www.bbc.co.uk/news/business-13188529</guid>
<pubDate>Wed, 11 May 2011 15:58:25 GMT</pubDate>
<media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/51580000/jpg/_51580546_011474775-1.jpg"/>
<media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/51580000/jpg/_51580545_011474775-1.jpg"/>
</item>

I am getting value of title, but it is not reading the other values like description, link

please help
 

mkvidyashankar

Active Member
Licensed User
Longtime User
I tried this but no result


Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Parser As SaxParser
Type news(title As String, descr As String, linkrss As String)
Dim mynews As List
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim panelrss As Panel
Dim listrss As ListView
Dim HttpClient1 As HttpClient
Dim HttpResponse1 As HttpResponse
Dim heading,linkrs,descr As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
activity.LoadLayout("Layout1")
panelrss.SetLayout(0,0,100%x,100%y)
listrss.SetLayout(0,0,100%x,100%y)
HttpClient1.Initialize("HttpClient1")
Parser.Initialize
mynews.Initialize
getfeed
listrss.Clear

End Sub

Sub Activity_Resume
listrss.Clear
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub getfeed
Dim rr As String
wm = ""
Dim request As HttpRequest
request.InitializeGet("http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml" )
request.Timeout = 10000 'set timeout to 10 seconds
If HttpClient1.Execute(request, 1) = False Then Return 'Will be false if there is already a running task (with the same id).
ProgressDialogShow("Fetching Data...")
End Sub
Sub HttpClient1_ResponseSuccess (Response As HttpResponse, TaskId As Int)
ProgressDialogHide
Dim result As InputStream
result = Response.GetInputStream 'GetString("UTF8") 'Convert the response to a string
Parser.Parse(result, "Parser")
result.Close
Dim nw As news
nw=mynews.Get(2)

'Label6.Text = wm
End Sub

Sub HttpClient1_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)
ProgressDialogHide
If StatusCode = -1 Then msg = "The phone is offline"
'If reason <> Null Then msg = msg & CRLF & Reason
ToastMessageShow (Reason, True)
End Sub
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)

If Parser.Parents.IndexOf("item") > -1 Then
If Name="title" Then heading=Text.ToString
Else If Name="description" Then descr=Text.ToString
'listrss.AddTwoLines(heading,descr)

End If
If heading.Length > 0 Then listrss.AddTwoLines(heading,descr)
End Sub
Sub parser_StartElement (Uri As String, Name As String, Attributes As Attributes)

End Sub


please help
 
Upvote 0
Top