Android Question Error in reading xml

mkvidyashankar

Active Member
Licensed User
Longtime User
I am trying to read xml file attached with this, it is found that it stops parsing at line no 20, not moving further, is there any problem with the code
B4X:
Sub Parser1_EndElement (Uri As String, Name As String, Text As StringBuilder)
   
    Dim media, pubdate As String
    Dim jk As Int =Parser1.Parents.IndexOf("item")
  If Parser1.Parents.IndexOf("item") > -1 Then
        If Name="title" Then heading=Text.ToString
        If Name="description" Then descr=Text.ToString
        If Name ="link" Then linkd=Text.ToString
        If Name="media" Then media=Text.ToString
        If Name="pubdate" Then pubdate=Text.ToString
    End If
    'If k < 40 Then
        If Name="title" AND heading <> ""  Then
            k=k+1
            list_feed.AddTwoLinesAndBitmap(heading,pubdate,Null)
        End If
        If Name="link" Then
            linkurl(k)=linkd
        End If
   
       
    'End If
End Sub

and how to get the image path which is under media node under each item
 

Attachments

  • NEWSXML.XML.zip
    7.7 KB · Views: 151

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are several problems in your code.

First one is that you should have empty catch blocks. At least add Log(LastException). Otherwise you will not be able to understand what is happening.

You should use HttpUtils2 to manage downloads. Your current code will fail on Android 4+:
B4X:
Sub Httpclient2_ResponseSuccess (Response As HttpResponse, TaskId As Int)
   ProgressDialogHide
   Dim result As InputStream
   result = Response.GetInputStream 'GetString("UTF8") 'Convert the response to a string
   Try
   Parser1.Parse(result, "Parser1") 'NetworkOnMainThread exception here
   Catch
   End Try
   result.Close
   'nw=mynews.Get(2)
'   If descr.Length > 200 Then descr = descr.SubString2(0,200)& "..."
'   If heading.Length > 0 Then list_feed.AddSingleLine(heading)
   'Label6.Text = wm   
End Sub
 
Upvote 0
Top