rss feed

mkvidyashankar

Active Member
Licensed User
Longtime User
In this RSS Feed I am trying to extract data in description and yweather tag. Dont know How to do it :sign0085:

please help


<item>
<title>
Conditions for Banashankari Stage 3, IN at 1:31 pm IST
</title>
<geo:lat>12.92</geo:lat>
<geo:long>77.55</geo:long>
<link>
Bangalore - Karnataka Weather Forecasts | Maps | News - Yahoo! Weather
</link>
<pubDate>Sat, 29 Oct 2011 1:31 pm IST</pubDate>
<yweather:condition text="Partly Cloudy" code="30" temp="26" date="Sat, 29 Oct 2011 1:31 pm IST"/>
<description>
<![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/30.gif"/><br /> <b>Current Conditions:</b><br /> Partly Cloudy, 26 C<BR /> <BR /><b>Forecast:</b><BR /> Sat - Showers. High: 26 Low: 19<br /> Sun - Scattered Thunderstorms. High: 26 Low: 19<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Banashankari_Stage_3__IN/*http://weather.yahoo.com/forecast/INXX0012_c.html">Full Forecast at Yahoo! Weather</a><BR/><BR/> (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]>
</description>
<yweather:forecast day="Sat" date="29 Oct 2011" low="19" high="26" text="Showers" code="11"/>
<yweather:forecast day="Sun" date="30 Oct 2011" low="19" high="26" text="Scattered Thunderstorms" code="38"/>
<guid isPermaLink="false">INXX0012_2011_10_30_7_00_IST</guid>
</item>
 

alfcen

Well-Known Member
Licensed User
Longtime User
Try with SaxParser

Hello mkvidyashankar,

THEORETICALLY, something like this should work (have not tested it).
However, the SaxParser might have problems with the "<yweather:" tag, in which
event you would need to parse the feed manually using String functions
and download the feed using GetString():

Dim feed as String
feed = Response.GetString("UTF8")
in Sub HttpClient1_ResponseSuccess (Response As HttpResponse, TaskId As Int)


B4X:
Sub Process_Globals
   Dim Parser As SaxParser
   Dim HttpClient1 As HttpClient
   Dim wm as String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
   Parser.Initialize
   HttpClient1.Initialize("HttpClient1")
    End If
    Request.InitializeGet("http://..................") 'your feed URL here
    If HttpClient1.Execute(Request, 1) = False Then Return
End Sub

Sub HttpClient1_ResponseSuccess (Response As HttpResponse, TaskId As Int)
   Dim Result As InputStream
   Result = Response.GetInputStream
   Parser.Parse(Result, "Parser")
   Result.Close
End Sub

Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
   If Parser.Parents.IndexOf("item") > -1 Then
      If Name = "yweather" Then                [COLOR="Red"]'error likely here[/COLOR]
          wm = wm & Text.ToString & CRLF
      Else If Name = "description" Then
          wm = wm & Text.ToString
      End if
   End If
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
In what way isn't it working? I tried it and it fetches the description node correctly.
The condition node should be extracted from the attributes:
B4X:
Sub Parser_StartElement (Uri As String, Name As String, Attributes As Attributes)
   If name = "condition" Then
      For i = 0 To Attributes.Size - 1
         Log("name=" & Attributes.GetName(i))
         Log("value=" & Attributes.GetValue(i))
      Next
   End If
End Sub
 
Upvote 0
Top