B4J Question How to extract list of NAMEs from an html/php document?

B4JExplorer

Active Member
Licensed User
Longtime User
Hi,

Do we have an existing way to get a list, just separated by carriage returns, of all of the INPUT components from a source file?

(Not from the website, but just from the html/php code. A file or a string).


So from a form that includes these rows:

<tr>
<td>
<br>
<input type = "text" name = "nme_organization_name" id = "id_organization_name" value = "<?php echo $organization_name;?>" required >
</td>
</tr>
<tr>
<td>
<label for="id_submitted_by"><b>Submitted By</b></label>
</td>
<td>
<input type = "text" name= "nme_submitted_by" id = "id_submitted_by" value = "<?php echo $submitted_by ; ?>" required >
</td>
</tr>


<tr>
<td>
</td>
<td align = "left">
<input type= "button" name="nme_delete_org_record" class = "bt_standard_button" value = "Delete" id = "id_delete_org_record" >
</td>
</tr>



(Note that sometimes there is a space between name, =, and the quote ; and sometimes not.)


, B4J would generate this list:


nme_organization_name
nme_submitted_by
nme_delete_org_record
 

William Lancee

Well-Known Member
Licensed User
Longtime User
B4X:
    Dim src As String = $"
<tr>
<td>
<br>
<input type = "text" name = "nme_organization_name" id = "id_organization_name" value = "<?php echo $organization_name;?>" required >
</td>
</tr>
<tr>
<td>
<label for="id_submitted_by"><b>Submitted By</b></label>
</td>
<td>
<input type = "text" name= "nme_submitted_by" id = "id_submitted_by" value = "<?php echo $submitted_by ; ?>" required >
</td>
</tr>


<tr>
<td>
</td>
<td align = "left">
<input type= "button" name="nme_delete_org_record" class = "bt_standard_button" value = "Delete" id = "id_delete_org_record" >
</td>
</tr>

    "$
    
    
    Dim v() As String = Regex.Split(" name", src)
    For j = 1 To v.Length - 1
        Dim s As String = v(j)
        Dim k As Int = s.IndexOf(QUOTE)
        Log(s.SubString2(k+1, s.IndexOf2(QUOTE, k+1)))
    Next
 
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
You can use Jsoup library, https://www.b4x.com/android/forum/threads/jsoup-html-parser.49152/#content ,to parse html, to get a list with attribute name (not tested)

B4X:
Dim htmlpage As String
Dim l As List:l.initialize
l=jsoup1.getElementsByAttribute(htmlpage,"name")

upload_2019-11-21_23-11-16.png
 
Upvote 0
Top