Android Question SaxParser with Wait For

SMOOTSARA

Active Member
Licensed User
Longtime User
Hello friends ?
How can I use the " SaxParser " library with Wait For ?

I've made a list (list_exchange_data) ,and I want to get list after "EndElement" metod ((EndElement (Uri As String, Name As String, Text As StringBuilder)))

B4X:
Sub Parser2_EndElement (Uri As String, Name As String, StringBuilder_Text As StringBuilder)
  

    Dim list_exchange_data As List
    list_exchange_data.Initialize
    list_exchange_data.Clear
    
    Dim local_str As String = ""

    If parser2.Parents.IndexOf("item") > -1 Then
        If     Name = "name" Then
            local_str=""
            local_str=get_icon_flag(StringBuilder_Text.ToString)&"#"&StringBuilder_Text.ToString
        Else If Name = "price" Then
            local_str=local_str&"#"&StringBuilder_Text.ToString
        Else If Name = "change" Then
            local_str=local_str&"#"&StringBuilder_Text.ToString
        Else If Name = "percent" Then
            local_str=local_str&"#"&StringBuilder_Text.ToString
            list_exchange_data.Add(local_str)
        End If
    End If

'    Log(list_exchange_data)
End Sub


Thanks ?
 

Toky Olivier

Active Member
Licensed User
Longtime User
Hello friends ?
How can I use the " SaxParser " library with Wait For ?

I've made a list (list_exchange_data) ,and I want to get list after "EndElement" metod ((EndElement (Uri As String, Name As String, Text As StringBuilder)))

B4X:
Sub Parser2_EndElement (Uri As String, Name As String, StringBuilder_Text As StringBuilder)
 

    Dim list_exchange_data As List
    list_exchange_data.Initialize
    list_exchange_data.Clear
   
    Dim local_str As String = ""

    If parser2.Parents.IndexOf("item") > -1 Then
        If     Name = "name" Then
            local_str=""
            local_str=get_icon_flag(StringBuilder_Text.ToString)&"#"&StringBuilder_Text.ToString
        Else If Name = "price" Then
            local_str=local_str&"#"&StringBuilder_Text.ToString
        Else If Name = "change" Then
            local_str=local_str&"#"&StringBuilder_Text.ToString
        Else If Name = "percent" Then
            local_str=local_str&"#"&StringBuilder_Text.ToString
            list_exchange_data.Add(local_str)
        End If
    End If

'    Log(list_exchange_data)
End Sub


Thanks ?
1. I think that the list_exchange_data should be a global variable not declared in the EndElement function. The initilization may be done when the activity starts and the Clear sub need to be called before you call Parse or Parse2 sub so that the list is cleared before you do the parsing.
2. I'm quite sure that the place of the "list_exchange_data.Add" is wrong. May be like this:
B4X:
Sub Parser2_EndElement (Uri As String, Name As String, StringBuilder_Text As StringBuilder)
 

 
   
    Dim local_str As String '="" Not needed

    If parser2.Parents.IndexOf("item") > -1 Then
        If     Name = "name" Then
            'local_str="" Not needed
            local_str=get_icon_flag(StringBuilder_Text.ToString)&"#"&StringBuilder_Text.ToString
        Else If Name = "price" Then
            local_str=local_str&"#"&StringBuilder_Text.ToString
        Else If Name = "change" Then
            local_str=local_str&"#"&StringBuilder_Text.ToString
        Else If Name = "percent" Then
            local_str=local_str&"#"&StringBuilder_Text.ToString
            
        End If
        If local_str <> "" then list_exchange_data.Add(local_str)
    End If

   Log(list_exchange_data)
End Sub
3. I never used a SaxParser... :)
 
Upvote 0

SMOOTSARA

Active Member
Licensed User
Longtime User
Hello Toky Olivier
I need to use the "wait for " method
for example

B4X:
Wait For (parser2) complete (Uri As String, Name As String, StringBuilder_Text As StringBuilder)

But I will not succeed
 
Upvote 0
Top