Android Question error using xml2map

jchal

Active Member
Licensed User
Longtime User
hi aal
i tryed the code below
RSS feed with url:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    Private ParsedData As Map
End Sub

Sub Globals
    Private ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        Dim xm As Xml2Map
        xm.Initialize
    ParsedData = xm.Parse("http://feeds.bbci.co.uk/news/world/rss.xml")
    
    End If
    Activity.LoadLayout("1")
    ListView1.SingleLineLayout.ItemHeight = 60dip
    Dim rss As Map = ParsedData.Get("rss")
    Dim channel As Map = rss.Get("channel")
    Dim items As List = channel.Get("item")
    For Each item As Map In items
        Dim title As String = item.Get("title")
        Dim link As String = item.Get("link")
        ListView1.AddSingleLine2(title, link)
    Next
End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
    Dim pi As PhoneIntents
    StartActivity(pi.OpenBrowser(Value))
End Sub
and i receive the following error
Logger connected to: Xiaomi Redmi Note 5A Prime
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 24 (Xml2Map)
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 5: not well-formed (invalid token)
at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:515)
at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:474)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:316)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
at anywheresoftware.b4a.objects.SaxParser.parse(SaxParser.java:80)
at anywheresoftware.b4a.objects.SaxParser.Parse(SaxParser.java:73)
at b4a.example.xml2map._parse2(xml2map.java:255)
at b4a.example.xml2map._parse(xml2map.java:90)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.main.afterFirstLayout(main.java:105)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6393)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
i will apriciate if you can tell me what i am doing wrong
also i have uploaded the following librarys
phone
XML2MAP
XUI and core
 

jchal

Active Member
Licensed User
Longtime User
what i am trying to achieve is to change the following code as it crashes my app on load
B4X:
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim resulturl As String
    resulturl = ""
    
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.
    Private rssView As CustomRSSView
    
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    Activity.LoadLayout("LDysplay")
    rssView.Initialize(Activity, Me, "rssView", 1dip, 100%y-50dip)

    Activity.Title = "BBC feeds"
            ProgressDialogShow("Fetching...")
            rssView.ParseRSS("http://feeds.bbci.co.uk/news/world/rss.xml")
        
        
    Main.result=""
End Sub

Sub rssView_FinishedLoading
    
    ProgressDialogHide

End Sub

Sub rssView_ItemClicked(URL As String)
    
    'On this even you will get the URL of a clicked item and process it as you wish
    Msgbox(URL, "Item Clicked")
    resulturl=URL
    StartActivity(AWebV)
End Sub

Sub rssView_ErrorMessage(Message As String)
    
    ProgressDialogHide
                
    Msgbox(Message, "Oops!")
                
End Sub

Sub Activity_KeyPress(KeyCode As Int) As Boolean

    If rssView.IsOpen = True Then
                
        rssView.HideCustomRSSView
                            
        Return True
                            
    End If
    
End Sub
how do i do it ?
i am getting con fused the old library has changed and since then i cant read and display Rss, the library i was using was customrssview
this is what i get and app stops
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.isis.myapp/files/rss.xml (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:449)
at njdude.customrssview.sample.customrssview._hc_responsesuccess(customrssview.java:282)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6393)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
 
Upvote 0

jchal

Active Member
Licensed User
Longtime User
to my understanding, there is now way to have rss feed on line any more but i must download it and then display it like it was an of line xml file
am i correct? if i am not can i have a small example it will help me to understand better
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
to my understanding, there is now way to have rss feed on line any more but i must download it and then display it like it was an of line xml file
am i correct? if i am not can i have a small example it will help me to understand better
No @jchal you're incorrect.

I have attached an example project for you to look at. In the attached example there are 2 ways to achieve what you are attempting to achieve.
  1. XML2Map
  2. XMLParser
Carefully study the attached code and hopefully you will figure it out for yourself. I know that you were taking about XML2Map, but still I decided to create an example using both methods mentioned above (because I stupidly started with XMLParser).


Enjoy...
 

Attachments

  • RSSFeed.zip
    9.2 KB · Views: 166
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
to my understanding, there is now way to have rss feed on line any more but i must download it and then display it like it was an of line xml file
There is no such thing. You cannot show anything that hasn't been downloaded first. I guess that the old library downloaded the resource for you. Fortunately it is very simple to download it.
 
Upvote 0

jchal

Active Member
Licensed User
Longtime User
thank you all
Peter Simpson i have some questions concerning the example as this was of a great help.
when i changed the link to https://www.theguardian.com/uk/rss i got some rubish html like <P>, <span> , <div> etch.
second question as i used custom list view, i could not make it look like and rss reader .
if you can help it will be mostly apricated.
i am attaching the code
 

Attachments

  • rss feed.zip
    10.6 KB · Views: 157
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
thank you all
Peter Simpson i have some questions concerning the example as this was of a great help.
when i changed the link to https://www.theguardian.com/uk/rss i got some rubish html like <P>, <span> , <div> etch.
second question as i used custom list view, i could not make it look like and rss reader .
if you can help it will be mostly apricated.
i am attaching the code
I don't need to look at your code to know what that is, it's html elements for formatting the news stories. If need be you can strip out the elements by first creating a list of elements (which you can get from the link below) that you need to remove. Loop through the RSS feed removing the elements, once the feed has been stripped of the html elements you will have a rss feed without html elements. It should not take you that long to do, just think of it like if you are replacing words in a string.
 
Upvote 0

jchal

Active Member
Licensed User
Longtime User
thank you all
i have found my way, one question how can i display a photo from the article is there a way?
Do feeds have a jpg image and if yes how i can get it?
 
Last edited:
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
@jchal
You need to learn how xml works.
Read the code in the attached file and learn how it works (try to understand it). I have included 2 ways to download the images, way 1 is inline, way 2 is by using wait for (and a separate sub). You need to learn how Wait For works. The attached code is easy enough for anybody to follow.

The rest is now 100% up to you, the rest is pretty simple and the forum search works perfect.

Forum search ;)
1620778993072.png



Enjoy...
 

Attachments

  • RSSFeed.zip
    11 KB · Views: 153
Upvote 0
Top