Android Question Trying to run the MiniHtmlParser example

DanteS

Member
Licensed User
Longtime User
I am trying to run the MiniHtmlParser example. I downloaded the class MiniHtmlParser and copied it to the Libraries of the B4A IDE.
I also downloaded the Example application that uses de class.

How can I run the app? I see that the active file seems to be the nonui.b4j file, but if I double click the file, the process ask for an application to open the file. If I choose B4A, the IDE opens, but with nothing inside.
What is the correct form to run a B4J file?
 

DonManfred

Expert
Licensed User
Longtime User
you can not run a b4j app in B4A.

Run the b4j file with B4J as it is a B4J-Project to see it in action. and also see the code.

Use the class MiniHtmlParser in your b4a-project and Implement the code to use it.
 
Last edited:
Upvote 0

DanteS

Member
Licensed User
Longtime User
Use the class MiniHtmlParser in your b4a-project and Implement the code to use it.
Thanks Don for your suggestion.

I opened the non-ui.b4j app code with Notes Block and used this code in a new project in B4A.

I can compile and install the new app and it opens correctly.

The button click event is executed correctly (it says the typical "Hello world")

Now I would like to execute a function or a method of the MiniHtmlParser class. What code should I write inside the button click event to do this?

The complete code is this.

Code of the new project:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
    Private HtmlParser As MiniHtmlParser
    Type CurrencyRate (Name As String, FromUSD As Double, ToUSD As Double)
    Private Rates As List

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub AppStart (Args() As String)
    Rates.Initialize
    HtmlParser.Initialize
    Dim root As HtmlNode = HtmlParser.Parse(File.ReadString(File.DirAssets, "rates.html"))
    'Find the table element
    Dim Table As HtmlNode = HtmlParser.FindNode(root, "table", HtmlParser.CreateHtmlAttribute("class", "ratesTable"))
    If Table.IsInitialized Then
        'find the tbody element
        Dim tbody As HtmlNode = HtmlParser.FindNode(Table, "tbody", Null)
        If tbody.IsInitialized Then
            'print the first tr element:
            HtmlParser.PrintNode(tbody.Children.Get(1))
            For Each tr As HtmlNode In HtmlParser.FindDirectNodes(tbody, "tr", Null)
                Dim tds As List = HtmlParser.FindDirectNodes(tr, "td", Null)
                Dim name As String = HtmlParser.GetTextFromNode(tds.Get(0), 0)
                
                Dim a As HtmlNode = HtmlParser.FindNode(tds.Get(1), "a", Null)
                Dim FromUSD As Double = HtmlParser.GetTextFromNode(a, 0)
                
                Dim a As HtmlNode = HtmlParser.FindNode(tds.Get(2), "a", Null)
                Dim ToUSD As Double = HtmlParser.GetTextFromNode(a, 0)
                Rates.Add(CreateCurrencyRate(name, FromUSD, ToUSD))
            Next
        End If
    Else
        Log("not found!!!")
    End If
    Log("***********************")
    For Each rate As CurrencyRate In Rates
        Log(rate)
    Next
End Sub

Public Sub CreateCurrencyRate (Name As String, FromUSD As Double, ToUSD As Double) As CurrencyRate
    Dim t1 As CurrencyRate
    t1.Initialize
    t1.Name = Name
    t1.FromUSD = FromUSD
    t1.ToUSD = ToUSD
    Return t1
End Sub
Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
'    AppStart ()
End Sub
 
Upvote 0
Top