Android Question XML2Map

kanati

Member
Licensed User
Longtime User
I add this library to my project and it fails to compile.

B4A Version: 9.00
Parsing code. Error
Error parsing program.
Error description: Unknown type: xmlbuilder
Are you missing a library reference?
Error occurred on line: 3 (Map2Xml)
Private builder As XMLBuilder


I have both xml2map and xmlsax (have tried with and without xmlsax) without any luck. Using version 9.00 of B4A.

Anyone have any idea why it appears the library itself is complaining about another library?
 

kanati

Member
Licensed User
Longtime User
(I would note that the program runs fine until I add the reference so it's not my code... it appears to be a problem with the library itself)

I also just verified that the default template program compiles file and without any changes at all, it fails immediately to compile with the above error when you add xml2map and xmlsax libraries to the project (though it is only the xml2map library which causes the error).
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

kanati

Member
Licensed User
Longtime User
Thanks. I'll give it a shot. I was getting some weird weird errors yesterday when I finally gave up on B4A but I'll add that library and give it another shot.

(I had strings that I was trying to apply to properties in a class and it was giving me numeric conversion errors even though no variables at all were numeric)
 
Upvote 0

kanati

Member
Licensed User
Longtime User
I'm not throwing errors now but I'm not getting data out of my xml either. This is probably my fault, but I'm not sure where I need to go from here.

B4X:
<TemperatureDataList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
    <Items>
        <TemperatureData>
            <ID>2258</ID>
            <IdentityID>3</IdentityID>
            <TimeStamp>2019-04-10T17:42:00</TimeStamp>
            <Temperature>76.82</Temperature>
            <Humidity>33.10</Humidity>
        </TemperatureData>
        <TemperatureData>
            <ID>2257</ID>
            <IdentityID>3</IdentityID>
            <TimeStamp>2019-04-10T17:37:00</TimeStamp>
            <Temperature>76.82</Temperature>
            <Humidity>33.30</Humidity>
        </TemperatureData>
        <TemperatureData>
            <ID>2256</ID>
            <IdentityID>3</IdentityID>
            <TimeStamp>2019-04-10T17:32:00</TimeStamp>
            <Temperature>76.82</Temperature>
            <Humidity>33.60</Humidity>
        </TemperatureData>
        <TemperatureData>
            <ID>2255</ID>
            <IdentityID>3</IdentityID>
            <TimeStamp>2019-04-10T17:27:00</TimeStamp>
            <Temperature>76.82</Temperature>
            <Humidity>33.70</Humidity>
        </TemperatureData>
    </Items>
</TemperatureDataList>

That's my XML...

And for snippets of my code:

B4X:
    Private TempData As Map 'in process_globals

    Private xm As Xml2Map   'in globals

    If FirstTime Then 'in activity_create()
        xm.Initialize  
    End If

    Dim xmlstring As String = h.GetString 'and this code is in a sub that is called when a refresh button is pressed...
  
    TempData = xm.Parse(xmlstring)
  
    For Each tmpdata As Map In GetElements(TempData, "TemperatureData")
        Log(tmpdata.Get("Temperature"))      
    Next

Nothing gets logged so I assume that nothing is being placed into TempData. The xmlstring is definitely populated with the above XML btw. That much I know.
 
Upvote 0

kanati

Member
Licensed User
Longtime User
neeeeever mind. I got it. :)

I neglected to get the temperaturedatalist first... and then the items... and then temperaturedata.
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Consider posting your working code snippet as future help for others.

Ps .. maybe investigate other options for initialising Xml2Map object , ie Starter Service, testing for IsInitialized etc.
Depending on your usage, it may created problems placing initialization in a If First Time condition.
 
Upvote 0
Top