Android Question how detect img tag rss

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
Hi.
The structure of rss is :
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>W3Schools Home Page</title>
<link>http://www.w3schools.com</link>
<description>Free web building tutorials</description>
<image>
<url>http://www.w3schools.com/images/logo.gif</url>
<title>W3Schools.com</title>
<link>http://www.w3schools.com</link>
</image>
<item>
<title>RSS Tutorial</title>
<link>http://www.w3schools.com/rss</link>
<description>New RSS tutorial on W3Schools</description>
</item>
</channel>
</rss>

How i detect img tag in rss?
 

sorex

Expert
Licensed User
Longtime User
quick and dirty...

B4X:
Log(rss.SubString2(rss.IndexOf("url")+4,rss.IndexOf("</url>")))
 
Upvote 0

KZero

Active Member
Licensed User
Longtime User
using XMLSax Library

B4X:
Sub Globals
Dim Parser As SaxParser
End Sub

Dim In As InputStream
In=File.OpenInput(File.DirAssets, "1.xml")
Parser.Initialize
Parser.Parse(In,"Parser")

Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
    If Name="url" Then
       Log(Text.ToString)
    End If
End Sub
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
there are several methods to get that data, it just depends on how you want to do it.

mine: small, library-less and ideal for beginners but quick and dirty
Kzero's: needs a library and more code
regex: too tricky for beginner

if the rss contains 2 or more images you better use Kzero's method as mine would only pick the first one unless your rewrite it a bit.
 
Upvote 0

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
using XMLSax Library

B4X:
Sub Globals
Dim Parser As SaxParser
End Sub

Dim In As InputStream
In=File.OpenInput(File.DirAssets, "1.xml")
Parser.Initialize
Parser.Parse(In,"Parser")

Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
    If Name="url" Then
       Log(Text.ToString)
    End If
End Sub
Thank you I successfull
 
Upvote 0
Top