B4J Question [SOLVED] How to read an xml tag like this: <INDIVIDUAL_PLACE_OF_BIRTH/>?

rosippc64a

Active Member
Licensed User
Longtime User
Hi All,
I have a huge xml. In it there is a node: <INDIVIDUAL_PLACE_OF_BIRTH/>. This is a normal empty node.
I read the xml with xml2map like below and I get an exception - only if I in release mode!:
(ClassCastException) java.lang.ClassCastException: java.lang.String cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap'
I can understand, this isn't a map, this is an empty node. But how can I check it?
I tried with: if lm is Map then ... end if. It works in debug mode, but not in release mode.
I tried try / catch / end try, It works in debug mode, but not in release mode.
I tried For Each lm As object In Codebase.GetElements(m, kk(0)) / if lm is map then ... It works in debug mode, but not in release mode.
I tried other ways also, but no success.

How can I find out, that it is an empty node?
thanks
Steven

B4X:
                    'kk(0) = "INDIVIDUAL_PLACE_OF_BIRTH"
                    For Each lm As Map In Codebase.GetElements(m, kk(0))                     
                        If lm.ContainsKey(kk(1)) Then   'here is an exception:
                            If attribute.Length > 0 Then
                                Dim mm As Map = lm.Get(kk(1))
                                Dim amapl As Map = mm.Get("Attributes")
                                If amapl.ContainsKey(attribute) Then
                                    Return amapl.Get(attribute)
                                Else
                                    Return Null
                                End If
                            Else
                                Return lm.Get(kk(1))
                            End If
                        End If
                    Next
                    ...

Sub GetElements (m As Map, key As String) As List
    Dim res As List
    If m.ContainsKey(key) = False Then
        res.Initialize
        Return res
    Else
        Dim value As Object = m.Get(key)
        If value Is List Then Return value
        res.Initialize
        res.Add(value)
        Return res
    End If
End [ATTACH type="full"]117724[/ATTACH]Sub
 

Attachments

  • 1628714753462.png
    1628714753462.png
    10.5 KB · Views: 105
Last edited:

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
I tried with: if lm is Map then ... end if.
This should work but i guess you are still using for each first and then testing if it is a map. if you have such ending blocks, better use for i instead of for each.

something like:

B4X:
dim l as list = Codebase.GetElements(m, kk(0)) 
for i = 0 to l.size -1
dim om as object = l.get(i)

if om is map then
om.as(map).Get(kk(1))
....
else
continue
 
Last edited:
Upvote 0
Top