Android Question HTML inner text

Rusty

Well-Known Member
Licensed User
Longtime User

Erel

B4X founder
Staff member
Licensed User
Longtime User
The question is whether all the html texts that you need to deal with look exactly like the above snippet?

If so then you can easily get this value with regex:
B4X:
Sub Button1_Click
   Dim html As String = $"
   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<body style="font-family: Calibri">
<p class="style2">
<strong>Dear Sir:</strong>
</p>
</body>
</html>
"$
   Dim m As Matcher = Regex.Matcher("<strong>([^>]+)</strong>", html)
   If m.Find Then
     Log(m.Group(1))
   End If
End Sub

Another option is to use JTidy to convert the html to XML and then parse it with a XML parser.
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
:) of course they are not all like that :)
it was a simple example.
However, your suggestion of JTIDY was excellent! Much better than the REGEX I've been using!
Thanks,
Erel
 
Upvote 0
Top