Android Question XmlSax & Rounding

Pencil3

Member
Licensed User
Using XmlSax on a XML and I'm running into a rounding issue that I can't figure out.

XML snippet:
B4X:
-<probe>
<name>Amp_3</name>
<value>4.3 </value>
<type>Amps</type>
</probe>

Using:
B4X:
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
    If parser.Parents.IndexOf("probe") > -1 Then
        If Name = "name" Then
            ProbeName = Text.ToString
        Else If ProbeName = "Amp_3" And Name = "value" Then
            ProbeResult = Text.ToString
        End If
    End If
    Log(ProbeName & " : " &(ProbeResult))
End Sub

And in my log I see:
Amp_3 : 4.9

What am I clearly overlooking?
 

OliverA

Expert
Licensed User
Longtime User
I don't get the code.
  1. Uri is passed but never used?
  2. You pass "Name" and check for it with the "If", but how to you expect it to get to the "Else If"
  3. So if "Name" is "name", "ProbeName" becomes "Text.ToString". Then the "If" ends. Then you log both "ProbeName" and "ProbeResult", but nothing has been really assigned to "ProbeResult" at all in this function, so it prints whatever ProbeResult has been set to before it enters this function.
  4. Global variables really confuse this function. If you would DIM ProbeResult in this function instead of outside the function, you would notice that this function does not set it (or at least in a way that you expect).
 
Upvote 0
Top