Then we would have a problem, Houston
Actually in this case there is no problem because it is a matter of reading a barcode and asking for the information only for that item.
RIghto... this modified (but no extra lines) XML field extraction Subroutine:
B4X:
Sub GetXMLField(XML As String, RecordID As String, FieldName As String) As String
Dim Pattern As String = "<NS2.*?id=""" & RecordID & """.*?<" & FieldName & " .*?>(.*?)</" & FieldName & ">"
Dim XMLMatcher As Matcher = Regex.Matcher(Pattern, XML.Replace(Chr(10), ""))
If XMLMatcher.Find Then
Return XMLMatcher.Group(1)
End If
Return "XML record " & RecordID & " field " & FieldName & " not found" 'or whatever you prefer to signify not found
End Sub
For RecordID = 1 To 5 'SampleXML only has records 1..4 ie no record 5
Log(RecordID & TAB & GetXMLField(SampleXML, RecordID, "Nombre"))
Next
results in:
Log ouput:
Waiting for debugger to connect...
Program started.
1 PRIMO PAT. LISA FAMILIAR 260 GRS X 12 B.
2 SECONDO PAT. LISA FAMILIAR 260 GRS X 12 B.
3 TERZO PAT. LISA FAMILIAR 260 GRS X 12 B.
4 QUARTO PAT. LISA FAMILIAR 260 GRS X 12 B.
5 XML record 5 field Nombre not found
Runtime efficiency is dismal but good enough for proof-of-concept mockup